#P8263. [Ynoi Easy Round 2020] TEST_8

[Ynoi Easy Round 2020] TEST_8

Problem Description

Given a 0101 string SS of length nn (a sequence consisting of 00 and 11, indexed by integers from 11 to nn).

The following operations are supported:

Operation 1: given l,r,kl, r, k, repeat the substring of the 0101 string from index ll to rr for kk times and put it back in place.

Operation 2: given l,r,kl, r, k, repeat the substring of the 0101 string from index ll to rr for kk times with reversal (specifically, for the ii-th repetition (1ik1 \leq i \leq k), if the binary representation of i1i - 1 contains an odd number of 11, then this repetition should be reversed left to right; otherwise it remains unchanged), and finally put it back in place.

Operation 3: given l,rl, r, delete the substring of the 0101 string from index ll to rr.

Operation 4: given kk, find the position of the kk-th 11 in the 0101 string from left to right. If kk exceeds the number of 11 in the 0101 string, output 1-1.

Input Format

The first line contains an integer nn.

The next line contains a 0101 string of length nn.

The next line contains an integer mm.

The next mm lines each start with an integer opop indicating the operation type.

If op=1op = 1 or op=2op = 2, the line then contains three integers l,r,kl, r, k.

If op=3op = 3, the line then contains two integers l,rl, r.

If op=4op = 4, the line then contains one integer kk.

Output Format

For each operation 4, output one line representing the answer.

11
11011100010
5
3 2 3
2 6 8 5
1 2 5 3
4 8
4 100
10
-1

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

It is guaranteed that 1lr1 \leq l \leq r \leq the length of the 0101 string before the operation.

In operations 1,2,41, 2, 4, 1k1081 \leq k \leq 10^8.

For 20%20\% of the testdata, n,mn, m, and the length of the 0101 string never exceed 2020.

For 40%40\% of the testdata, there is only one operation 4, and there is no operation 2.

For 100%100\% of the testdata, 1n,m1051 \leq n, m \leq 10^5, and the length of the 0101 string never exceeds 10810^8.

Sample explanation:

The 1st operation: 1[10]11100010->111100010, deleted 10.

The 2nd operation: 11110[001]0->11110[001,100,100,001,100]0->111100011001000011000, repeated 001 for 5 times, where the 2nd, 3rd, and 5th times are reversed.

The 3rd operation: 1[1110]0011001000011000->1[1110,1110,1110]0011001000011000->11110111011100011001000011000, repeated 1110 for 3 times.

The 4th operation: 111101110[1]1100011001000011000, the 8th 11 is at the 10th position in the 0101 string.

The 5th operation: there is no 100th 11, output -1.

Translated by ChatGPT 5