Zigu Zagu solution codeforces
You have a binary stringof length consisting only of digits and .
You are givenqueries. In the -th query, you are given two indices and such that .
Let. You are allowed to do the following operation on :
- Choose two indices and such that . Let be the substring . Then for all , the condition has to hold. Note that is always a valid substring.
- Delete the substring from .
For each of thequeries, find the minimum number of operations needed to make an empty string.
Note that for a string, denotes the subsegment .
The first line contains two integersand ( ) — the length of the binary string and the number of queries respectively.
The second line contains a binary stringof length ( ).
Each of the nextlines contains two integers and ( ) — representing the substring of each query.
5 3 11011 2 4 1 5 3 5
1 3 2
10 3 1001110110 1 10 2 5 5 10
4 2 3
In the first test case,
- The substring is , so we can do one operation to make the substring empty.
- The substring is
, so we can do one operation on to make , then use two more operations to make the substring empty.
I am the Founder and the creator of the blog neoideasblog.com where we share latest trivia questions and answers on a daily basis.