Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:求各路大神帮忙看看哪里有问题……过了所有能找到的数据,但是WAIn Reply To:Re:求各路大神帮忙看看哪里有问题……过了所有能找到的数据,但是WA Posted by:yanph2003 at 2016-04-07 14:21:56 // 您好,很同情您的遭遇,由于调错能力不佳,故附上一份AC代码O(∩_∩)O #include <algorithm> #include <iostream> using namespace std; struct NODE { int d; int size; NODE *s[2]; NODE *f; int lazy; int lazy_num; int MIN; }t[400001],*root,*rf; int tot = 0, N; int size(NODE *p) { if(p) return p->size; else return 0; } void update(NODE *p) { p->size = 1 + size(p->s[0]) + size(p->s[1]); int MIN = p->d; if(p->s[0]) MIN = min(MIN, p->s[0]->MIN + p->s[0]->lazy_num); if(p->s[1]) MIN = min(MIN, p->s[1]->MIN + p->s[1]->lazy_num); p->MIN = MIN; } void pushdown(NODE *p) { if(p->lazy) { swap(p->s[0],p->s[1]); if(p->s[0]) p->s[0]->lazy ^= 1; if(p->s[1]) p->s[1]->lazy ^= 1; p->lazy = 0; } if(p->lazy_num) { p->d += p->lazy_num; p->MIN += p->lazy_num; if(p->s[0]) p->s[0]->lazy_num += p->lazy_num; if(p->s[1]) p->s[1]->lazy_num += p->lazy_num; p->lazy_num = 0; } } void rotate(NODE *p, int type) { NODE *f = p->f; NODE *gf = p->f->f; NODE *s = p->s[!type]; f->s[type] = s; if(s) s->f = f; p->s[!type] = f; f->f = p; p->f = gf; gf->s[f==gf->s[1]] = p; update(f); update(p); if(root==f) root = p; } void splay(NODE *p, NODE *goal) { while(p->f!=goal) { if(p->f->f==goal) { rotate(p,p==p->f->s[1]); } else { NODE *f = p->f; NODE *gf = f->f; int d = (gf->s[0]==f); if(p==f->s[d]) rotate(p,d), rotate(p,!d); else rotate(f,!d), rotate(p,!d); } } } NODE *find(NODE *p,int k) { pushdown(p); if(size(p->s[0])>=k) { return find(p->s[0],k); } else if(size(p->s[0])==k-1) { return p; } else { return find(p->s[1],k-1-size(p->s[0])); } } void ADD(int x,int y,int d) { if(x>y) swap(x,y); NODE *p = find(root,x-1); splay(p,rf); p = find(root,y+1); splay(p,root); p->s[0]->lazy_num+=d; update(p); update(p->f); } void INSERT(int k, int d) { NODE *new_node = &t[++tot]; new_node->size = 1; new_node->d = d; new_node->MIN = d; NODE *p = find(root,k); splay(p,rf); p = find(root,k+1); splay(p,root); p->s[0] = new_node; new_node->f = p; update(p); update(p->f); } void DELETE(int k) { NODE *p = find(root,k-1); splay(p,rf); p = find(root,k+1); splay(p,root); p->s[0] = NULL; update(p); update(p->f); } void REVERSE(int x, int y) { if(x>y) swap(x,y); NODE *p = find(root,x-1); splay(p,rf); p = find(root,y+1); splay(p,root); p->s[0]->lazy^=1; } void REVOLVE(int x, int y, int dis) { if(x>y) swap(x,y); dis%=(y-x+1); dis%=(dis+y-x+1); if(dis==0) return; else { REVERSE(x,y); REVERSE(x,x+dis-1); REVERSE(x+dis,y); } } int MIN(int x, int y) { if(x>y) swap(x,y); NODE *p = find(root,x-1); splay(p,rf); p = find(root,y+1); splay(p,root); return (p->s[0]->MIN + p->s[0]->lazy_num); } int main(void) { cin>>N; root = &t[++tot]; root->d = root->MIN = (1<<31); root->size = 1; rf = &t[++tot]; rf->s[0] = root; root->f = rf; NODE *p; int d; for(int i = 1; i<=N; i++) { cin>>d; p = &t[++tot]; p->size = 1; p->MIN = p->d = d; p->f = root; root->s[1] = p; splay(p,rf); } p = &t[++tot]; p->size = 1; p->MIN = p->d = 1000000000; p->f = root; root->s[1] = p; splay(p,rf); int M; cin>>M; char op[0xf]; int u,v,w; while(M--) { cin>>op; if(strcmp(op,"ADD")==0) { cin>>u>>v>>w; ADD(u+1,v+1,w); } else if(strcmp(op,"REVERSE")==0) { cin>>u>>v; REVERSE(u+1,v+1); } else if(strcmp(op,"REVOLVE")==0) { cin>>u>>v>>w; REVOLVE(u+1,v+1,w); } else if(strcmp(op,"INSERT")==0) { cin>>u>>v; INSERT(u+1,v); } else if(strcmp(op,"DELETE")==0) { cin>>u; DELETE(u+1); } else if(strcmp(op,"MIN")==0) { cin>>u>>v; cout<<MIN(u+1,v+1)<<endl; } } system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator