Time Limit: 1 Sec
Memory Limit: 256 MB
Submission:7
AC:0
Score:0
Ali is going to line up for the welcome of Miss N. At the beginning, N people stand in a row.
Ali has two operations at a time:
1. Let the team of Miss Yingbin, numbered Y, receive the last team of Miss Yingbin numbered X (the order remains unchanged). If X Y is already in the same team, then no movement is made.
2. Ask how many welcome ladies are behind Miss Yingbin, number X.
For each set of data: the first line contains two integers N, M
The next M line contains M operations
There are two types of operations: T X Y, corresponding to the first operation, Q X, corresponding to the second operation.
For each query, output the answer
input:
2 2
T 1 2
Q 1
output:
1
1 <= N <=35000 , M <= 350000