记录编号 |
328083 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2013]火柴排队 |
最终得分 |
100 |
用户昵称 |
LOSER |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.269 s |
提交时间 |
2016-10-23 18:31:13 |
内存使用 |
4.89 MiB |
显示代码纯文本
- #include<queue>
- #include<cstdio>
- #include<cstring>
- #include<iostream>
- #include<algorithm>
- using namespace std;
- #define maxn 100010
- #define mod 99999997
- #define LL long long
- LL n,s[maxn];
- struct Node{
- LL pos,data;
- bool operator < (const Node & a) const
- {return data<a.data;}
- }a[maxn],b[maxn];
- struct Fenwick_tree{
- #define Lowbit(x) ((x)&(-x))
- LL c[maxn];
- void Insert(LL x,LL y){
- for(;x<=n;x+=Lowbit(x)) c[x]+=y,c[x]%=mod;
- }
- LL Getsum(LL x){ LL tot=0;
- for(;x>0;x-=Lowbit(x)) tot+=c[x];
- return tot;
- }
- }T;
- int main(){
- freopen("MatchNOIP2013.in","r",stdin); freopen("MatchNOIP2013.out","w",stdout);
- scanf("%lld",&n);
- for(LL i=1;i<=n;i++) scanf("%lld",&a[i].data),a[i].pos=i;
- for(LL i=1;i<=n;i++) scanf("%lld",&b[i].data),b[i].pos=i;
- sort(a+1,a+n+1); sort(b+1,b+n+1);
- for(LL i=1;i<=n;i++){
- s[a[i].pos]=b[i].pos;
- } //寻找s数组的逆序对总和
- LL ans=0;
- for(LL i=1;i<=n;i++){
- ans+=T.Getsum(n)-T.Getsum(s[i]);
- ans%=mod;
- T.Insert(s[i],1);
- } printf("%lld\n",ans);
- getchar(); getchar();
- fclose(stdin); fclose(stdout);
- return 0;
- }