记录编号 328083 评测结果 AAAAAAAAAA
题目名称 [NOIP 2013]火柴排队 最终得分 100
用户昵称 GravatarLOSER 是否通过 通过
代码语言 C++ 运行时间 0.269 s
提交时间 2016-10-23 18:31:13 内存使用 4.89 MiB
显示代码纯文本
  1. #include<queue>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. using namespace std;
  7. #define maxn 100010
  8. #define mod 99999997
  9. #define LL long long
  10. LL n,s[maxn];
  11. struct Node{
  12. LL pos,data;
  13. bool operator < (const Node & a) const
  14. {return data<a.data;}
  15. }a[maxn],b[maxn];
  16. struct Fenwick_tree{
  17. #define Lowbit(x) ((x)&(-x))
  18. LL c[maxn];
  19. void Insert(LL x,LL y){
  20. for(;x<=n;x+=Lowbit(x)) c[x]+=y,c[x]%=mod;
  21. }
  22. LL Getsum(LL x){ LL tot=0;
  23. for(;x>0;x-=Lowbit(x)) tot+=c[x];
  24. return tot;
  25. }
  26. }T;
  27. int main(){
  28. freopen("MatchNOIP2013.in","r",stdin); freopen("MatchNOIP2013.out","w",stdout);
  29. scanf("%lld",&n);
  30. for(LL i=1;i<=n;i++) scanf("%lld",&a[i].data),a[i].pos=i;
  31. for(LL i=1;i<=n;i++) scanf("%lld",&b[i].data),b[i].pos=i;
  32. sort(a+1,a+n+1); sort(b+1,b+n+1);
  33. for(LL i=1;i<=n;i++){
  34. s[a[i].pos]=b[i].pos;
  35. } //寻找s数组的逆序对总和
  36. LL ans=0;
  37. for(LL i=1;i<=n;i++){
  38. ans+=T.Getsum(n)-T.Getsum(s[i]);
  39. ans%=mod;
  40. T.Insert(s[i],1);
  41. } printf("%lld\n",ans);
  42. getchar(); getchar();
  43. fclose(stdin); fclose(stdout);
  44. return 0;
  45. }