Created
January 1, 2013 18:25
-
-
Save utkarshl/4429155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include"segment_tree.cpp" | |
#include"algorithm" | |
#include"stdio.h" | |
struct node{ | |
int min,sum; | |
void merge(node& l,node& r){ | |
sum = l.sum+r.sum; | |
min = std::min(l.min,l.sum+r.min); | |
} | |
}; | |
void flip(node& n){ | |
n.min*=-1; | |
n.sum=n.min; | |
} | |
int main(){ | |
for(int i=0;i<10;i++){ | |
printf("Test %d:\n",i+1); | |
segtree<node> s; | |
int n; | |
scanf("%d",&n); | |
char inp[n+1]; | |
scanf("%s",inp); | |
node arr[n+1]; | |
for(int i=0;i<n;i++) | |
arr[i].min=arr[i].sum=inp[i]=='('?1:-1; | |
arr[n].min=arr[n].sum=0; | |
s.init(n,arr,arr[n]); | |
int m; | |
scanf("%d",&m); | |
while(m--){ | |
int k; | |
scanf("%d",&k); | |
if(k) | |
s.update<&flip>(k-1); | |
else{ | |
node x=s.query(0,100000000); | |
printf("%s\n",(x.sum==0&&x.min==0)?"YES":"NO"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can you explain a little bit that how your code is able to solve the problem