luogu#P5226. [SCOI2015] 小凸解密码
[SCOI2015] 小凸解密码
Problem Description
Xiao Tu obtained a password dial. The dial is evenly divided into sectors. Each sector contains a digit and a symbol ( or ). The decryption method is as follows.
First, choose a starting position, and record the digits and symbols clockwise into arrays and , respectively. The decryption is done as follows:
- .
- When :
- If is
+, then . - If is
*, then .
- If is
After finishing the operations, you obtain an array of length . Then, starting from , write the array clockwise into a ring. The decryption is complete. The resulting ring is called the answer ring.
Now Xiao Tu has an instruction list with 2 types of operations. One type is an update operation, which changes the digit and symbol at a position on the original dial. The other type is a query operation, described as follows:
- First, start from the position given in the instruction and complete the decryption to obtain the answer ring.
- On the answer ring, there may be some consecutive ’s. Such consecutive ’s are called a zero interval. Find the zero interval that is farthest from , and output this distance (the distance between a zero interval and is defined as the minimum, among all ’s in the interval, of the distance from that to ).
Input Format
The first line contains two integers , representing the size of the password dial and the number of instructions.
The next lines each contain an integer and a character, giving the digit array and symbol array on the dial in clockwise order.
The next lines give the instructions in order. The first integer on each line indicates the instruction type:
- If the first integer is
1, this instruction is an update operation. It is followed by two integers and a character , representing the position to modify, and the digit and character at that position after modification. - If the first integer is
2, this instruction is a query operation. It is followed by an integer , representing the starting position for decryption in this operation.
The positions on the dial are numbered from to .
The testdata is guaranteed to be valid, i.e., , , and is + or *.
Output Format
For each query operation, output one line with the answer. If there is no on the answer ring, output −1.
5 8
0 *
0 *
0 *
0 *
0 *
2 0
1 0 1 +
1 2 1 +
2 3
1 1 1 +
1 3 1 +
1 4 1 +
2 4
0
2
-1
Hint
Sample Explanation:
For the st query, the answer ring is . There is only zero interval, and is inside it, so the distance is .
For the nd query, the answer ring is . There are zero intervals. The distance between and is , and the distance between and is , so the answer is .
For the rd query, the answer ring is . There is no zero interval, so the answer is −1.
Constraints:
For of the testdata, , .
For of the testdata, , .
For of the testdata, .
Translated by ChatGPT 5