This page is still under construction.

Parts of this page are still being built. What you see may change.

Balls

Time limit1sMemory limit256 MB

Summary
Maintain a set of unit-diameter balls on a line with a wall; support insertions at free spots and repeatedly roll the leftmost ball, propagating collisions until it stops, then print all final positions.
Level

Medium7 of 10

Topics
Simulation, Hash map, Union-find, Implementation
Solved
No attempts yet

Problem

There are NN balls on the number line, each of diameter 11, numbered from 11 through NN. Ball ii's leftmost point is located at position p_ip\_i. Additionally, there is an immovable wall located at position PP. You have to process QQ queries of one of the following forms:

  • "1 xx": Insert a new ball with its leftmost point at xx. If this spot is already occupied, do nothing.
  • "2": Roll the leftmost ball to the right. When a rolling ball (possibly after moving distance zero) collides with a stationary ball, it stops, and the stationary ball begins rolling in the same direction. Specifically, a rolling ball stops at the position 11 less than the position of the object it collided with. A ball stops when it reaches the wall.

Calculate the final positions of the balls.

Input

The first line contains three integers NN, QQ, and PP: the initial number of balls, the number of queries, and the position of the wall (1≤N,Q≤1051 \leq N, Q \leq 10^5, N≤P≤109N \leq P \leq 10^9).

The second line contains NN integers p_1,p_2,…,p_Np\_1, p\_2, \ldots, p\_N (0≤p_i<P0 \leq p\_i < P). It is guaranteed the positions are distinct.

The next QQ lines describe the queries and may have one of the following forms:

  • "1 xx" (0≤x<P0 \leq x < P)
  • "2"

Output

Print out the final positions of the balls in increasing order on a single line, separated by spaces.

Examples2

  1. Example 1

    Input
    2 1 5
    1 3
    2
    
    Expected output
    2 4
    
  2. Example 2

    Input
    5 3 10
    1 8 3 7 2
    2
    1 4
    2
    
    Expected output
    1 3 5 6 8 9