BRCKTS  Brackets
We will call a bracket word any word constructed out of two sorts of characters: the opening bracket "(" and the closing bracket ")". Among these words we will distinguish correct bracket expressions. These are such bracket words in which the brackets can be matched into pairs such that
 every pair consists of an opening bracket and a closing bracket appearing further in the bracket word
 for every pair the part of the word between the brackets of this pair has equal number of opening and closing brackets
 replacement  changes the ith bracket into the opposite one
 check  if the word is a correct bracket expression
Task
Write a program which
 reads (from standard input) the bracket word and the sequence of operations performed,
 for every check operation determines if the current bracket word is a correct bracket expression,
 writes out the outcome (to standard output).
Input
Ten test cases (given one under another, you have to process all!). Each of the test cases is a series of lines. The first line of a test consists of a single number n (1<=n<=30000) denoting the length of the bracket word. The second line consists of n brackets, not separated by any spaces. The third line consists of a single number m  the number of operations. Each of the following m lines carries a number k denoting the operation performed. k=0 denotes the check operation, k>0 denotes replacement of kth bracket by the opposite.
Output
For every test case your program should print a line:
Test i:
where i is replaced by the number of the test
and in the following lines, for every check operation in the ith test
your program should print a line with the word
YES,
if the current bracket word is a correct bracket expression, and a line
with a word
NO otherwise.
(There should be as many lines as check operations in the test.)
Example
Input: 4 ()(( 4 4 0 2 0 [and 9 test cases more] Output: Test 1: YES NO [and 9 test cases more]Warning: large Input/Output data, be careful with certain languages
hide comments
Tarik Sahni:
20151023 14:06:40
Took a lot of time


kartikay singh:
20151022 05:15:28
nice problem B)


:.Mohib.::
20150925 10:26:33
Nice one....!! 

just_code21:
20150801 06:40:30
nice one ! Last edit: 20150824 21:23:56 

kejriwal:
20150725 15:52:45
nice SegTree..AC in 0.65 sec..but anyonewho did it using Binary indexed tree..i am getting WA donno why..please share your approach !! :( Last edit: 20150726 20:21:28 

Ravi kumar:
20150723 12:25:32
solved using segment tree 

uptoyou:
20150627 05:55:43
i got TLE using stack, what should i do? 

Asheesh Pathak:
20150623 20:00:55
Ny1 got AC using stack... by the way, new idea no! B) 

Prismatic:
20150616 10:44:26
Lol =)) forget to write 'Test i' :)) 

xxbloodysantaxx:
20150606 08:19:07
Dont forget to print that Test 1:

Added by:  Adam Dzedzej 
Date:  20040615 
Time limit:  11s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: NODEJS PERL6 VB.NET 
Resource:  Internet Contest Pogromcy Algorytmow(Algorithm Tamers) 2003 Round IV 