首页 技术 正文
技术 2022年11月6日
0 收藏 543 点赞 659 浏览 913 个字

题意:找到最小改变对数使a数组的第i大和b数组的第i大相等

则先将a,b,数组编号再排序,则数组显示的就是排名第i的数的编号

再关键一步:c[a[i].id]=b[i].id

实质上就是新建一个数组,按照现有a数组的排布,和b数组进行比较,看是否有逆序对存在,有则需要更换,故再求逆序对即可

#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define dec(i,x,y) for(register int i=x;i>=y;i--)
#define LL long long
#define int long long
using namespace std;
const int mod=;
const int N=2e6+;
inline int read(){
int x=,f=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-;ch=getchar();}
while(isdigit(ch)){x=(x<<)+(x<<)+(ch^);ch=getchar();}
return x*f;}int n,ans,c[N],k[N];
pair<int,int> a[N],b[N];
inline void add(int x,int d){for(int i=x;i<=n;i+=i&(-i)) k[i]+=d;}
inline int query(int x){int ans=;for(int i=x;i;i-=i&(-i)) ans+=k[i];return ans;}
signed main(){
n=read();
rep(i,,n) a[i].first=read(),a[i].second=i;
rep(i,,n) b[i].first=read(),b[i].second=i;
sort(a+,a++n);sort(b+,b++n);
rep(i,,n) c[a[i].second]=b[i].second;
dec(i,n,) ans=(ans+query(c[i]))%mod,add(c[i],);
printf("%lld\n",ans%mod);return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,027
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857