Artem wants to create a basic multiset of integers. He wants these structure to support operations of three types:
But what about time machine? Artem doesn't simply apply operations to the multiset one by one, he now travels to different moments of time and apply his operation there. Consider the following example.
Note that Artem dislikes exceptions so much that he assures that after each change he makes all delete operations are applied only to element that is present in the multiset. The answer to the query of the third type is computed at the moment Artem makes the corresponding query and are not affected in any way by future changes he makes.
Help Artem implement time travellers multiset.
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of Artem's queries.
Then follow n lines with queries descriptions. Each of them contains three integers ai, ti and xi (1 ≤ ai ≤ 3, 1 ≤ ti, xi ≤ 109) — type of the query, moment of time Artem travels to in order to execute this query and the value of the query itself, respectively. It's guaranteed that all moments of time are distinct and that after each operation is applied all operations of the first and second types are consistent.
For each ask operation output the number of instances of integer being queried at the given moment of time.
6 1 1 5 3 5 5 1 2 5 3 6 5 2 3 5 3 7 5
1 2 1
3 1 1 1 2 2 1 3 3 1
0 题目大意:给定一个标号为1到n的序列,每次执行一个操作,使奇偶位置的两个数交换或者整个序列旋转一定长度,求最终序列。 分析:考虑到开始的奇偶子序列各自的相对位置不变而且互不影响,我们只需要记录1,2两个位置的变动就行了。#include <cstdio> #include <iostream> using namespace std; int n,m,q,x,num,ans[1000001]; int Got(int x) { if(x & 1 == 1) return x+1; return x-1; } int got(int x) { while(x < 0) x += n; x = x % n; if(x == 0) return n; return x; } int main() { scanf("%d%d",&n,&q); int a = 1,b = 2; for(int i = 1;i <= q;i++) { scanf("%d",&x); if(x == 2) { a = Got(a); b = Got(b); } else { scanf("%d",&num); a = got(a+num); b = got(b+num); } } for(int i = 1;i <= n/2;i++) ans[got(a+(i-1)*2)] = 2*i-1; for(int i = 1;i <= n/2;i++) ans[got(b+(i-1)*2)] = 2*i; for(int i = 1;i <= n;i++) cout<<ans[i]<<" "; }