TheShuMo @ 2023-12-23 22:01:57
RT
#include<bits/stdc++.h>
#define int long long
#define pb push_back
namespace IO {
#define int long long
#define gh getchar
inline int read(){char ch=gh();int x=0;bool t=0;while(ch<'0'||ch>'9') t|=ch=='-',ch=gh();while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();return t?-x:x;}
inline char getc(){char ch=gh();while(ch<'a'||ch>'z') ch=gh();return ch;}
inline void write(int x){if(x < 0){putchar('-');x = -x;}if(x > 9){write(x / 10);}putchar((x % 10 + '0'));}
}
using namespace IO;
using namespace std;
const int Maxn = 2e6 + 10;
struct Node{
int ls, rs;
int val, pri, sz;
}t[Maxn];
int cnt, root;
void newnode(int x){cnt++;
t[cnt].ls = t[cnt].rs = 0; t[cnt].val = x;t[cnt].sz = 1;
t[cnt].pri = rand();
}
void update(int x){
t[x].sz = t[t[x].ls].sz + t[t[x].rs].sz + 1;
}
void spilt(int u, int x,int &L,int &R){
if(u == 0){
L = 0; R = 0;
return;
}
if(t[u].val <= x){
L = u;
spilt(t[u].rs, x, t[u].rs, R);
}else {
R = u;
spilt(t[u].ls, x, L, t[u].ls);
}
update(u);
}
int merge(int L, int R){
if(L == 0 || R == 0) return L + R;
if(t[L].pri > t[R].pri){
t[L].rs = merge(t[L].rs, R); update(L); return L;
} else {t[R].ls = merge(L,t[R].ls), update(R); return R;}
}
void insert(int x){
int L, R;
spilt(root,x,L,R);
newnode(x);
int temp = merge(L, cnt);
root = merge(temp, R);
}
void del(int x){
int L,R,tp;
spilt(root,x,L,R);
spilt(L,x-1,L,tp);
tp = merge(t[tp].ls, t[tp].rs); // ��? = x ???��p???��??????����??��??��?????????????��????.
root = merge(merge(L,tp),R); // L: < x p: = x R : > x??merge??L?��???��??????R?��?��?????��??
}int lst = 0, ans = 0;
int rnk(int x){int L, R;
spilt(root,x-1,L,R);
lst = (t[L].sz+1);
// cout << lst;
root = merge(L, R);
}
int kth(int u, int k){
if(k == t[t[u].ls].sz + 1) return u;
else if(k <= t[t[u].ls].sz) return kth(t[u].ls, k); // ??������??��
else if(k > t[t[u].ls].sz)return kth(t[u].rs, k - t[t[u].ls].sz-1); // ???��???????��????
}
signed main(){
// freopen("P6136_2.in","r",stdin);
int n,m;
cin >> n >> m;
srand(time(NULL));
int tp;
for(int i = 1; i <= n; i++){
cin >> tp;
insert(tp);
}
for(int i = 1; i <= m; i++){
// cout << lst << endl;
int op, x; cin >> op >> x; x ^= lst;
// cout << op <<' '<< x << endl;
if(op == 1) {insert(x);}
if(op == 2) {del(x);}
if(op == 3) {rnk(x);}
if(op == 4) {lst = t[kth(root, x)].val; }
if(op == 5) {int L, R; spilt(root, x - 1, L, R); int p = t[kth(L,t[L].sz)].val; lst = p; root = merge(L,R);}
if(op == 6) {int L, R; spilt(root, x, L, R); int p = t[kth(R,1)].val; lst = p; root = merge(L,R);}
if(op > 2) ans ^= lst;
} cout << ans;
}
by TheShuMo @ 2023-12-23 22:03:24
@Scene
by TheShuMo @ 2023-12-23 22:03:48
普通过了
by sto_5k_orz @ 2023-12-23 22:27:54
来写 pbds
by TheShuMo @ 2023-12-24 07:12:30
一个一个功能注释完调过了,但是为什么把
int rnk(int x){int L, R;
spilt(root,x-1,L,R);
lst = (t[L].sz+1);
// cout << lst;
root = merge(L, R);
}
if(op == 3) {rnk(x);}
改成
int rnk(int x){int L, R;
spilt(root,x-1,L,R);
int p = (t[L].sz+1);
// cout << lst;
root = merge(L, R);
return p;
}
if(op == 3) {lst = rnk(x);}
就不会RE了? @sto_5k_orz
by sto_5k_orz @ 2023-12-24 10:00:47
@TheShuMo 我不会平衡树,我只会 RBIT
by Scene @ 2023-12-24 10:08:40
@TheShuMo int函数不返回好像编译都过不了吧(
by TheShuMo @ 2023-12-24 10:19:27
@Scene 过了编译但是改void以后还是会WA几个?
有点抽象了
by Scene @ 2023-12-24 10:44:06
zzz