Submit | All submissions | Best solutions | Back to list |
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 i-th 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 k-th 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 i-th 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
Added by: | Adam Dzedzej |
Date: | 2004-06-15 |
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 |
hide comments
|
||||||||||||||
2018-01-09 09:30:26
cakewalk segment tree :D. |
||||||||||||||
2017-12-17 21:06:17
half century!!! |
||||||||||||||
2017-12-16 09:33:06
my 100th. |
||||||||||||||
2017-12-14 19:22:08
am doing with segment trees, still giving TLE..Any suggestions please. solution is here <snip> Done..Juzt a suggestion ..Dont use cin,cout....Use scanf,printf..It caused me 7 TLEs Last edit: 2023-01-22 18:23:59 |
||||||||||||||
2017-12-09 11:42:25
can anyone explain how the calculation of partial sums helpful in solving this problem. or any blog's link where i can read about it |
||||||||||||||
2017-11-02 19:59:58 SACHIN YADAV
I am getting TLE with java. Any suggestion please |
||||||||||||||
2017-09-16 13:52:16
Think about how to check for balanced condition! Rest is just implementation in ST. |
||||||||||||||
2017-07-30 12:58:16
Very easy ....just few things (count of unmatched open and closed brackets)............ Especially print the ******"Test i"********** |
||||||||||||||
2017-07-19 20:09:47 sharif ullah
Just consider t<=10 ,otherwise it may give u Runtime error, it give huge number of runtime errror~~~~~~ |
||||||||||||||
2017-06-28 12:03:21
Getting WA if size of segment tree is 13*10^4 but got accepted with 13*10^7....could i know why this happened? Last edit: 2017-06-28 12:04:27 |