hdu 2688 Rotate(树状数组)
2012-09-21 18:52
162 查看
有个序列找出所有正序数的对数,R是将S,E之间的数rotate。
Q是求当前的正序数。
树状数组+模拟
这道题坑的啊,用G++交的话TLE了,C++就540ms
Q是求当前的正序数。
树状数组+模拟
这道题坑的啊,用G++交的话TLE了,C++就540ms
/* Problem ID: meaning: Analyzing: */ #include <iostream> #include <algorithm> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<vector> using namespace std; typedef struct even{int y1,y2,x;}even; #define clr(A,k) memset(A,k,sizeof(A)) #define FOR(i,s,t) for(int i=(s); i<(t); i++) #define LL long long #define BUG puts("here!!!") #define print(x) printf("%d\n",x) #define STOP system("pause") #define eps 1e-8 #define PI acos(-1.0) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define maxn 3000006 #define maxm 10005 int lowbit(int x){ return x&(-x); } LL gcd(LL a,LL b) {return a?gcd(b%a,a):b;} int A[maxn],C[maxm],n; void update(int pos,int val){ while(pos<=maxm-1){ C[pos]+=val; pos+=lowbit(pos); } } int query(int pos){ int ret=0; while(pos>0){ ret+=C[pos]; pos-=lowbit(pos); } return ret; } int main(){ int m; char op[5]; while(~scanf("%d",&n)){ clr(C,0); LL sum=0; for(int i=0;i<n;i++){ scanf("%d",&A[i]); update(A[i],1); sum+=query(A[i]-1); } scanf("%d",&m); int S,E; while(m--){ scanf("%s",op); if(op[0]=='Q'){ printf("%I64d\n",sum); }else { scanf("%d%d",&S,&E); int temp=A[S]; for(int i=S;i<E;i++){ A[i]=A[i+1]; if(A[i]>temp) sum--; else if(A[i]<temp) sum++; } A[E]=temp; } } } return 0; }
相关文章推荐
- HDU-2688-Rotate-(树状数组)
- HDU 2688 Rotate(树状数组---求正序数)
- hdu 2688 Rotate 树状数组
- hdu 2688_Rotate(树状数组,求顺序对数)
- hdu 2688 Rotate (树状数组)
- HDU 2688 Rotate 树状数组
- hdu_2688_Rotate(树状数组)
- hdu_2688_Rotate(树状数组)
- hdu_2688_Cow Sorting(树状数组)
- hdu 2688 树状数组求 序列对
- hdu1166之树状数组入门
- HDU-3966 Aragorn's Story (树链剖分 树状数组 区间修改 点查询)(2011 Multi-University Training Contest 13)
- hdu 1556 树状数组 成段更新 单点求值
- [ACM] hdu 1166 敌兵布阵(树状数组)
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
- hdu 1556(树状数组)
- hdu 1541 Stars(树状数组)
- 【二维树状数组】hdu 1559 最大子矩阵
- 【HDU 3333】【离线询问 树状数组 前驱思想】Turing Tree【 求区间中不同的数的和】
- HDU 1166 敌兵布阵(简单树状数组)