0_0_29611499_24710.cpp: In function 'void insert(int, int)':
0_0_29611499_24710.cpp:23:535: error: expected statement at end of input
int sum(int *c,int x){ int ret = 0; while(x>0) { ret += c[x]; x -= x&-x; } return ret;}struct data{ int s,a[305],c[20010]; data *nxt; data() { MS(c,0); nxt = NULL; }};int n,m;data *root;void insert(int x,int pos){ data *now = root; if(root == NULL) { root = new data; root->s = 1; root->a[1] = x; add(root->c,x,1); return; } while(pos > now->s && now->nxt != NULL) { pos -= now->s; now = now->nxt; } memmove(now->a+pos+1,now->a+pos,sizeof(int)*(now->s-pos+1)); now->a[pos] = x; add(now->c,x,1); now->s++; if(now->s == 2*lim)//·ÖÁÑ { data *lst = new data; lst->nxt = now->nxt; now->nxt = lst; memcpy(lst->a+1,now->a+lim+1,sizeof(int)*lim); lst->s = now->s = lim; for(int i = 1; i <= lim; ++i) { add(now->c,lst->a[i],-1); add(lst->c,lst->a[i],1); } }}int find(int pos){ data *now = root; while(pos > now->s && now->nxt != NULL) { pos -= now->s; now = now->nxt; } return now->a[pos];}int calc(int pos){ data *now = root; int ret = 0; int x = find(pos); while(pos > now->s && now->nxt != NULL) { ret += sum(now->c,20000) - sum(now->c,x); pos -= now->s; now = now->nxt; } for(int i = 1; i < pos; ++i) if(now->a[i] > x) ret++; for(int i = pos+1; i <= now->s; ++i) if(now->a[i] < x) ret++; while(now->nxt != NULL) { now = now->nxt; ret += sum(now->c,x-1); } return ret;}void del(int pos){ data *now = root; while(pos > now->s && now->nxt != NULL) { pos -= now->s; now = now->nxt; } add(now->c,now->a[pos],-1); memmove(now->a+pos,now->a+pos+1,sizeof(int)*(now->s-pos)); now->s--;}void destroy(data *now){ if(now->nxt != NULL) destroy(now->nxt); delete now;}void solve(){ root = NULL;int ope,u,v,ans = 0; int x,y; for(int i = 1; i <= n; ++i) { scanf("%d",&u); insert(u,i); ans += calc(i); } for(int i = 1; i <= m; ++i) { scanf("%d",&ope); if(ope == 1) { scanf("%d",&x); ans -= calc(x); del(x); } else { scanf("%d%d",&x,&y); insert(y,x+1); ans += calc(x+1); } printf("%d\n",ans); } destroy(root);}int main(){ while(~scanf("%d%d",&n,&m)) solve(); return 0;}
^
0_0_29611499_24710.cpp:23:535: error: expected '}' at end of input
|