#P7505. Moving Terracotta Warriors on a Number Line

    ID: 20700 Type: Default 1000ms 256MiB

Moving Terracotta Warriors on a Number Line

Moving Terracotta Warriors on a Number Line

You are given n terracotta warriors standing on a number line. The position of the i-th warrior is given by \(a_i\), which is not guaranteed to be sorted in any order.

The warriors can only stand within the inclusive range \([-k, k]\). If any warrior moves outside that range, it is removed from the lineup permanently.

You will be given m commands. There are three types of commands:

  1. "1 x": All warriors move \(x\) units in the positive direction.
  2. "2 x": All warriors move \(x\) units in the negative direction.
  3. "3": Report the current number of warriors staying in the allowed range.

After each move command (type 1 or 2), any warrior that ends up with a position \(p\) such that \(p k\) is removed and will not be considered in the subsequent commands.

Your task is to output the answer for every command of type 3.

Note: The positions and movements are given as integers and all operations are applied to all warriors simultaneously.

inputFormat

The first line contains three integers \(n\), \(m\), and \(k\) where \(n\) is the number of warriors, \(m\) is the number of commands, and \(k\) defines the allowed range \([-k, k]\).

The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\), representing the initial positions of the warriors.

The following \(m\) lines each contain a command in one of the three formats mentioned above. For move commands (types 1 and 2), the format is "1 x" or "2 x" (without quotes) where \(x\) is an integer. For a query command, the line contains only "3".

outputFormat

For each command of type 3, output an integer representing the number of warriors remaining in the range \([-k, k]\). Each answer should be printed on a new line in the order the query commands appear.

sample

5 6 10
1 2 3 -5 10
3
1 5
3
2 10
3
3
5

4 4 4

</p>