Another bracket sequence
All submissions for this problem are available.
Here's another simple task, a sequence of characters of size n is given and the sequence contains only '(' and ')'.A sequence is defined as balanced sequence by the following rules:
- An empty sequence is balanced.
- A sequence of the form (A) is balanced if A is balanced.
- A sequence of the form AB is balanced if A and B both are balanced.
There will be some operations performed on the sequence. In every operation characters at 2 positions are permanently swapped. And your task is to determine whether the sequence is balanced after every operation.It is guaranteed that initial sequence will have equal number of both characters.
Operations are performed on updated string
- The first line contain a string of characters '(' and ')'. The length of the string will always be even.
- Next line will contain q,the number of operations.
- Next q lines contain two indices l and r which are to be swapped in that operation.
After every query check if the sequence is balanced or not and if it is balanced print "Yes" else print "No".
Input()))(( 3 0 0 2 5 4 5
OutputNo Yes No
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.