ColinKIA @ 2023-03-07 19:34:50
rope内部是由可持久化平衡树实现现的,支持
rope 的操作方法[不要看块状链表,往下看]
然后不能通过此题
求解释或调
#include <bits/stdc++.h>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace std;
int n,m,last,ans;
rope<int> a;
int main(){
scanf("%d %d",&n,&m);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
a.insert(lower_bound(a.begin(),a.end(),x)-a.begin(),x);
}
while(m--){
int opt,x;
scanf("%d %d",&opt,&x);
x^=last;
if(opt==1){
a.insert(lower_bound(a.begin(),a.end(),x)-a.begin(),x);
}else if(opt==2){
int l=0,r=a.size()-1,k=-1;
while(l<=r){
int mid=(l+r)/2;
if(a[mid]>=x){
r=mid-1;
k=mid;
}else{
l=mid+1;
}
}
a.erase(k,1);
}else if(opt==3){
int l=0,r=a.size()-1,k=-1;
while(l<=r){
int mid=(l+r)/2;
if(a[mid]>=x){
k=mid;
r=mid-1;
}else{
l=mid+1;
}
}
//printf("%d\n",k+1);
last=k+1;
}else if(opt==4){
//printf("%d\n",a[x-1]);
last=a[x-1];
}else if(opt==5){
int l=0,r=a.size()-1,k=-1;
while(l<=r){
int mid=(l+r)/2;
if(a[mid]>=x){
r=mid-1;
}else{
k=mid;
l=mid+1;
}
}
//printf("%d\n",a[k]);
last=a[k];
}else{
int l=0,r=a.size()-1,k=-1;
while(l<=r){
int mid=(l+r)/2;
if(a[mid]>x){
r=mid-1;
k=mid;
}else{
l=mid+1;
}
}
//printf("%d\n",a[k]);
last=a[k];
}
if(opt<=2) continue;
ans^=last;
}
printf("%d",ans);
return 0;
}
/*
20
1 964673
5 968705
4 1
3 964673
5 965257
1 915269
1 53283
3 964673
3 53283
3 53283
1 162641
5 973984
1 948119
2 915269
2 53283
6 959161
1 531821
1 967521
2 531821
1 343410
*/
by accomplishment @ 2023-03-07 20:27:29
额我觉得这题还是正经写平衡树有意义,别拿ST投机取巧。这样20行就搞完了
by UltiMadow @ 2023-03-07 21:58:57
@ColinKIA 您套了个二分是不是两个
by ColinKIA @ 2023-03-08 08:16:21
@UltiMadow 两个log 3秒也可以过呀?
by UltiMadow @ 2023-03-08 13:44:14
@ColinKIA 不行吧 我单