Visit Them All

 You are given a binary string 

S of length N.

Let G be a complete directed graph of N vertices numbered from 1 to N. There is a directed edge going from vertex u to v if one of the following is true:

  • Su=Sv and u<v
  • SuSv and u>v

For example, if S=1010 then G looks like this:

mDULZlh_d.webp?maxwidth=760&fidelity=grand

You will be given Q queries of two different types:

  • 1 L R - Flip all the bits in S in range [L,R] and update G accordingly.
  • 2 L R X - Find whether there is a path that starts from vertex X and visits each vertex in G[L,R] exactly once (a hamiltonian path in other words).

G[L,R] is the subgraph induced by the vertices in the range [L,R] and the edges connecting them. For example, if S=1010 then G[2,4] consists of the vertices 23, and 4, and the three edges 2443, and 32.

Input Format

  • The first line contains two integers, N and Q.
  • The second line contains a binary string S of length N.
  • The ith line of the next Q lines contains the description of the ith query.

Output Format

For each query of type 2, print a single line containing YES if there's a hamiltonian path starting from vertex X, or NO otherwise.

You may print each character of the string in uppercase or lowercase (for example, the strings yEsyesYes and YES will all be treated as identical).

Constraints

  • 1N,Q5105
  • For queries of type 11LRN
  • For queries of type 21LXRN

Subtasks

  • Subtask #1 (100 points): original constraints

Sample Input 1 

5 7
11011
2 1 5 3
2 3 5 3
2 3 5 4
1 4 5
2 1 5 2
1 2 3
2 3 5 4

Sample Output 1 

YES
NO
YES
NO
YES

Explanation

Here's what G initially looks like:

MXGV6XP_d.webp?maxwidth=760&fidelity=grand

  • First query: 31245 is a possible hamiltonian path.
  • Second query: There's no hamiltonian path that visits the vertices 34, and 5 which starts from 3.
  • Third query: 453 is a possible hamiltonian path.
  • Fourth query: Flip the bits in the range [4,5] so S becomes equal to 11000.
  • Fifth query: There's no hamiltonian path that visits the vertices 1234, and 5 which starts from 2.
  • Sixth query: Flip the bits in the range [2,3] so S becomes equal to 10100.
  • Seventh query: 453 is a possible hamiltonian path.
Previous
Next Post »