1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
| #include "ybwhead/ios.h"
const int maxn = 2e6 + 10;
struct fhq_treap
{
struct node
{
int ch[2], val;
unsigned int pri, siz;
} p[maxn];
int tot, root;
void update(int x)
{
p[x].siz = p[p[x].ch[0]].siz + p[p[x].ch[1]].siz + 1;
}
int new_node(int v)
{
p[++tot].siz = 1;
p[tot].val = v;
p[tot].pri = rand() * rand();
return tot;
}
int merge(int x, int y)
{
if (!x || !y)
return x + y;
if (p[x].pri < p[y].pri)
{
p[x].ch[1] = merge(p[x].ch[1], y);
update(x);
// cout << p[p[x].ch[1]].siz<<' '<<p[p[x]] << endl;
return x;
}
else
{
p[y].ch[0] = merge(x, p[y].ch[0]);
update(y);
// cout << p[y].siz << endl;
return y;
}
}
void split(int now, int k, int &x, int &y)
{
if (!now)
{
x = y = 0;
return;
}
if (p[now].val <= k)
x = now, split(p[now].ch[1], k, p[now].ch[1], y);
else
y = now, split(p[now].ch[0], k, x, p[now].ch[0]);
update(now);
}
int kth(int now, int k)
{
while (1)
{
if (k <= p[p[now].ch[0]].siz)
now = p[now].ch[0];
else if (k == p[p[now].ch[0]].siz + 1)
return now;
else
k -= p[p[now].ch[0]].siz + 1, now = p[now].ch[1];
}
}
void insert(int x)
{
int xx, yy;
split(root, x, xx, yy);
root = merge(merge(xx, new_node(x)), yy);
// cout << p[root].siz << endl;
}
void erase(int x)
{
int xx, yy, zz;
split(root, x, xx, yy);
split(xx, x - 1, xx, zz);
zz = merge(p[zz].ch[0], p[zz].ch[1]);
root = merge(merge(xx, zz), yy);
}
int rank(int x)
{
int xx, yy;
split(root, x - 1, xx, yy);
int zz = p[xx].siz + 1;
root = merge(xx, yy);
return zz;
}
int kkth(int x)
{
// cout << root << endl;
return p[kth(root, x)].val;
}
int lower(int x)
{
int xx, yy;
// cout << x << endl;
split(root, x - 1, xx, yy);
// puts("1");
// cout << kth(xx, p[xx].siz) << endl;
int zz = p[kth(xx, p[xx].siz)].val;
root = merge(xx, yy);
return zz;
}
int upper(int x)
{
int xx, yy;
split(root, x, xx, yy);
int zz = p[kth(yy, 1)].val;
// cout << kth(yy, 1) << endl;
root = merge(xx, yy);
return zz;
}
} tr;
int n, m;
int main()
{
yin >> n >> m;
for (int i = 1; i <= n; i++)
{
int x;
yin >> x;
tr.insert(x);
}
int ans = 0, last = 0;
while (m--)
{
int opt, x;
yin >> opt >> x;
x ^= last;
if (opt == 1)
tr.insert(x);
if (opt == 2)
tr.erase(x);
if (opt == 3)
ans ^= (last = tr.rank(x));
if (opt == 4)
ans ^= (last = tr.kkth(x));
if (opt == 5)
ans ^= (last = tr.lower(x));
if (opt == 6)
ans ^= (last = tr.upper(x));
}
yout << ans << endl;
}
|