QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8704. Queueing

Statistics

There are several people lining up. Initially, the queue is empty. At each time $t (t=1, 2, \dots, n)$, one of the following events occurs:

  1. $x$: A new person joins the queue. Their ID is assigned sequentially. They stand behind the person with ID $x$ ($x=0$ means they stand at the front of the queue).
  2. $i, y$: Let $t'$ be the time when the person with ID $i$ joined the queue. The operation at time $t'$ is modified to $1\ y$.
    • This modification affects all operations occurring after time $t'$.
  3. $z$: Query the current position of the person with ID $z$ in the queue.

Input

The first line contains two integers $sub$ and $n$, representing the subtask ID and the number of operations, respectively.

Then $n$ lines follow. Each line starts with an integer $opt$ representing the operation type.

If $opt=1$, input one integer $x$.

If $opt=2$, input two integers $i, y$.

If $opt=3$, input one integer $z$.

It is guaranteed that for all operations, including modified operations, the people involved are already in the queue when the operation occurs.

Output

For each operation of type $3$, output one integer per line representing the position.

Examples

Input

0 8
1 0
1 1
1 2
3 2
2 2 0
3 1
3 2
3 3

Output

2
3
1
2

Note

Explanation of the example:

After the third operation, the queue is $1, 2, 3$.

After the fifth operation, the queue is $2, 3, 1$.

Subtasks

For all test cases, it is guaranteed that $1 \leq n \leq 300000$ and that $x, i, y, z$ are valid.

Subtask 0, 4 pts: $n \leq 500$.

Subtask 1, 19 pts: $opt \neq 2$.

Subtask 2, 21 pts: The number of operations of type $3$ does not exceed $200$.

Subtask 3, 23 pts: $opt, x, i, y, z$ are generated uniformly at random within valid ranges.

Subtask 4, 33 pts: No special restrictions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.