November_Rain @ 2022-12-10 11:44:17
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <iomanip>
#include <utility>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <bitset>
#define int long long
#define ll long long
#define ull unsigned long long
#define re register
#define mod1 998244353
#define mod2 1000000007
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define pb(x) push_back(x)
#define lowbit(x) x & (-x)
#define gcd(a,b) __gcd(a,b)
#define mid ((l + r) >> 1)
#define rep(i,a,b) for(re int i(a);i <= b;++ i)
#define rrep(i,a,b) for(re int i(a);i >= b;i --)
using namespace std;
inline int read(){
re int x = 0,f = 1;
re char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)){
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
const int M = 1e6 + 1;
struct Splay{
int root;
int tot;
struct T{
int fa;
int ch[2];
int v;
int cnt;
int size;
}t[M];
inline void maintain(int x){
t[x].size = t[t[x].ch[0]].size + t[t[x].ch[1]].size + t[x].cnt;
}
inline bool get(int x){
return x == t[t[x].fa].ch[1];
}
inline void clear(int x){
t[x].ch[0] = t[x].ch[1] = t[x].fa = t[x].v = t[x].cnt = t[x].size = 0;
}
inline void rotate(int x){
int y = t[x].fa;
int z = t[y].fa;
int chk = get(x);
t[y].ch[chk] = t[x].ch[chk ^ 1];
if(t[x].ch[chk ^ 1]) t[t[x].ch[chk ^ 1]].fa = y;
t[x].ch[chk ^ 1] = y;
t[y].fa = x;
t[x].fa = z;
if(z) t[z].ch[y == t[z].ch[1]] = x;
maintain(y);
maintain(x);
}
inline void splay(int x){
for(re int f = t[x].fa;f = t[x].fa,f;rotate(x))
if(t[f].fa) rotate(get(x) == get(f) ? f : x);
root = x;
}
inline void insert(int k){
if(!root){
t[++ tot].v = k;
t[tot].cnt ++;
root = tot;
maintain(root);
return;
}
int cur = root;
int f = 0;
while(1){
if(t[cur].v == k){
t[cur].cnt ++;
maintain(cur);
maintain(f);
splay(cur);
break;
}
f = cur;
cur = t[f].ch[t[f].v < k];
if(!cur){
t[++ tot].v = k;
t[tot].cnt ++;
t[tot].fa = f;
t[f].ch[t[f].v < k] = tot;
maintain(tot);
maintain(f);
splay(tot);
break;
}
}
}
inline int rnk(int x){
int res = 0;
int cur = root;
while(1){
if(x < t[cur].v) cur = t[cur].ch[0];
else{
res += t[t[cur].ch[0]].size;
if(x == t[cur].v){
splay(cur);
return res + 1;
}
res += t[cur].cnt;
cur = t[cur].ch[1];
}
}
}
inline int kth(int k){
int cur = root;
while(1){
if(t[cur].ch[0] && k <= t[t[cur].ch[0]].size) cur = t[cur].ch[0];
else{
k -= t[t[cur].ch[0]].size + t[cur].cnt;
if(k <= 0){
splay(cur);
return t[cur].v;
}
cur = t[cur].ch[1];
}
}
}
inline int pre(){
int cur = t[root].ch[0];
if(!cur) return cur;
while(t[cur].ch[1]) cur = t[cur].ch[1];
splay(cur);
return cur;
}
inline int nxt(){
int cur = t[root].ch[1];
if(!cur) return cur;
while(t[cur].ch[0]) cur = t[cur].ch[0];
splay(cur);
return cur;
}
inline void del(int k){
rnk(k);
if(t[root].cnt > 1){
t[root].cnt --;
maintain(root);
return;
}
if(!t[root].ch[0] && !t[root].ch[1]){
clear(root);
root = 0;
return;
}
if(!t[root].ch[0]){
int cur = root;
root = t[root].ch[1];
t[root].fa = 0;
clear(cur);
return;
}
if(!t[root].ch[1]){
int cur = root;
root = t[root].ch[0];
t[root].fa = 0;
clear(cur);
return;
}
int cur = root;
int tmp = pre();
t[t[cur].ch[1]].fa = root;
t[root].ch[1] = t[cur].ch[1];
clear(cur);
maintain(root);
}
}st;
//#define OJ
//#define debug
signed main(){
#ifdef OJ
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
int n = read();
int ans = 0;
while(n --){
int op = read();
int x = read();
if(op == 1){
st.insert(x);
}
if(op == 2){
st.del(x);
}
if(op == 3){
st.insert(x);
ans ^= st.rnk(x);
st.del(x);
}
if(op == 4){
ans ^= st.kth(x);
}
if(op == 5){
st.insert(x);
ans ^= st.t[st.pre()].v;
st.del(x);
}
if(op == 6){
st.insert(x);
ans ^= st.t[st.nxt()].v;
st.del(x);
}
printf("%lld",ans);
}
#ifdef debug
printf("\nTime used = %lf", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
by November_Rain @ 2022-12-10 11:44:44
rt
by 樱雪喵 @ 2022-12-10 12:32:07
@November_Rain 则每次操作的
您是不是没异或啊qaq
by November_Rain @ 2022-12-10 17:18:38
@樱雪喵
%%% sto 樱雪喵 orz %%%
中午拿教室大屏幕敲的
没有缩放看不清题 bug巨多
感谢提醒!!!
by 樱雪喵 @ 2022-12-10 17:20:38
@November_Rain 怎么拿大屏幕都能卷/jk/jk 不过 orz()
by November_Rain @ 2022-12-10 18:45:14
@樱雪喵
%%% sto 樱雪喵 orz %%% qwq