Balanced bracket strings and queries
Time limit2sMemory limit1024 MB
Point updates change characters in a string of '(', ')', and '*', and range queries ask whether the stars in a substring can be filled to form a balanced bracket string.
- Level
Medium6 of 10
- Topics
- String, Segment tree, Greedy
- Solved
- No attempts yet
Problem
This problem was adapted lightly from an online judge problem that inspired the author.
Balanced bracket string is a property of strings defined as follows.
- The empty string is a balanced bracket string.
- If is a balanced bracket string, then , which wraps in brackets, is also a balanced bracket string.
- If and are balanced bracket strings, then , their concatenation, is also a balanced bracket string.
You are given a string of length made only of '(', ')', and '*'. You must process queries of the following two types.
1: Replace the -th character of with . is one of'(',')','*'. ()2: Replace each'*'in the substring with'(',')', or the empty string , choosing freely for each one. Then concatenate the remaining characters in their original order. Determine whether the result can be a balanced bracket string. ()
Can you solve all queries fast enough?
Input
The first line contains the length of and the number of queries , separated by a space. ()
The second line contains the string of length . Every character of is one of '(', ')', '*'.
The next lines each contain one query, one of the two types described above.
Output
For each query of type 2, print 'Yes' if the substring can be turned into a balanced bracket string, and 'No' otherwise, each on its own line.