#P7505. 「Wdsr-2.5」小小的埴轮兵团
「Wdsr-2.5」小小的埴轮兵团
Background
Zhang Dao Ou Mo Gong is the leader of the Haniwa army.
As the Haniwa commander, training the Haniwa army is a very common task.
Problem Description
Mo Gong gives an order to make the Haniwa stand in a line. You may think they are standing on a number line, and each Haniwa’s position is the number on the number line under its feet. Mo Gong will tell you that the position of the -th Haniwa is . It is not guaranteed that is in increasing order.
The length of the number line is limited to the range . That is, if a Haniwa moves out of this range, it leaves the line, and will never return to the line again.
To train the Haniwa, Mo Gong issues commands. There are 3 types:
- Command 1: All Haniwa move units in the positive direction of the number line.
- Command 2: All Haniwa move units in the negative direction of the number line.
- Command 3: Call the roll in order, and count how many Haniwa are currently in the line.
However, Mo Gong found that the Haniwa army is so large that performing these operations becomes very slow. Even so, Mo Gong still wants you to output the results of all Command 3.
Input Format
The first line contains integers , with meanings as described in the statement.
The second line contains integers , representing the positions of the Haniwa.
The next lines each contain or positive integers describing one command. First is an integer indicating the type of the command. If , then an integer is also given.
Output Format
For each Command 3, output one integer: the number of Haniwa that are still in the line.
3 4 3
-1 1 2
2 3
3
1 5
3
2
1
Hint
Explanation for Sample 1
There are three Haniwa in total. Initially, their positions are .
- After the first operation, all Haniwa move left by units, and the positions become . The first Haniwa is moved out of the number line.
- After the second operation, output the current number of Haniwa, which is .
- After the third operation, all Haniwa move right by units, and the positions become . The second Haniwa is moved out of the number line.
- After the fourth operation, output the current number of Haniwa, which is .
Samples 2 and 3
See the attached files provided.
Constraints
- For of the testdata, .
- For another of the testdata, .
- For of the testdata, , , and .
Translated by ChatGPT 5