Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <algorithm>
- using namespace std;
- int a,b,c,d,e,f;
- struct point
- {
- int x;
- int y;
- };
- point tree[4*30000];
- char q[30000+9];
- void moguce()
- {
- if(tree[1].x==0 && tree[1].y==0)printf("YES\n");
- else printf("NO\n");
- return;
- }
- void ini()
- {
- int b=0;
- for(b=1;b<a;b*=2){}
- //printf("%d\n",b+a-1);
- for(int i=b+a-1;i>1;--i)
- {
- if(i%2==1)
- {
- //printf("Cvor %d %d %d\n",i,tree[i].x,tree[i].y);
- tree[i/2].x=tree[i].x;
- tree[i/2].y=tree[i].y;
- }
- else
- {
- //ako lijevom treba ) a desni ih ima više onda moramo vidjeti koji ima više i u to zabilježiti koje
- int br=0;
- //printf("Cvor %d. %d-> %d %d -> %d %d\n",i/2,i,tree[i].x,tree[i].y,tree[i/2].x,tree[i/2].y);
- if(tree[i/2].y>tree[i].x && tree[i].x>0){tree[i/2].y-=tree[i].x;}
- else if(tree[i/2].y<=tree[i].x && tree[i/2].y>0){tree[i/2].x+=(tree[i].x-tree[i/2].y);tree[i/2].y=0;}
- else
- {
- tree[i/2].y+=tree[i].y;
- tree[i/2].x+=tree[i].x;
- }
- }
- }
- /*for(int i=1;i<=b+a-1;++i)
- {
- printf("%d. %d %d\n",i,tree[i].x,tree[i].y);
- }*/
- }
- void postavi(int pos)
- {
- int broj=1;
- for(broj=1;broj<a;broj*=2){}
- int pozicija=broj+pos;
- //printf("%d\n",pozicija);
- tree[pozicija].x=1-tree[pozicija].x;
- tree[pozicija].y=1-tree[pozicija].y;
- int pozicija2=pozicija;
- pozicija2/=2;
- while(pozicija2>0)
- {
- tree[pozicija2].x=tree[2*pozicija2+1].x;
- tree[pozicija2].y=tree[2*pozicija2+1].y;
- if(tree[pozicija2].y>tree[2*pozicija2].x && tree[2*pozicija2].x>0){tree[pozicija2].y-=tree[2*pozicija2].x;}
- else if(tree[pozicija2].y<=tree[2*pozicija2].x && tree[pozicija2].y>0){tree[pozicija2].x+=(tree[2*pozicija2].x-tree[pozicija2].y);tree[pozicija2].y=0;}
- else
- {
- tree[pozicija2].y+=tree[2*pozicija2].y;
- tree[pozicija2].x+=tree[2*pozicija2].x;
- }
- pozicija2/=2;
- }
- return;
- }
- int tt(int cvor,int from,int to,int a,int b)
- {
- if(from>=a && to<=b)
- {
- return tree[cvor].x;
- }
- int m1,m2;
- if((from+to)>=a)m1=tt(cvor*2,from,(from+to)/2,a,b);
- if((from+to)+1<=b)m2=tt(cvor*2+1,(from+to)/2+1,to,a,b);
- return max(m1,m2);
- }
- int main()
- {
- int p=0;
- while(scanf("%d",&a) == 1)
- {
- scanf("%s",q);
- scanf("%d",&b);
- printf("Test %d:\n",p+1);
- ++p;
- int ba=1;
- for(ba=1;ba<a;ba*=2){}
- for(int i=0;i<a;++i)
- {
- if(q[i]=='(')tree[i+ba].x=1;
- if(q[i]==')')tree[i+ba].y=1;
- }
- ini();
- for(int i=0;i<b;++i)
- {
- scanf("%d",&c);
- if(c==0){moguce();}
- else postavi(c-1);
- }
- for(int i=1;i<ba+a+6;++i)tree[i].x=0,tree[i].y=0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement