qsceszthn @ 2021-06-05 17:24:30
是ub了么?
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
namespace nqio{const unsigned R=4e5,W=4e5;char*a,*b,i[R],o[W],*c=o,*d=o+W,h[40],*p=h,y;bool s;struct q{void r(char&x){x=a==b&&(b=(a=i)+fread(i,1,R,stdin),a==b)?-1:*a++;}void f(){fwrite(o,1,c-o,stdout);c=o;}~q(){f();}void w(char x){*c=x;if(++c==d)f();}q&operator>>(char&x){do r(x);while(x<=32);return*this;}q&operator>>(char*x){do r(*x);while(*x<=32);while(*x>32)r(*++x);*x=0;return*this;}template<typename t>q&operator>>(t&x){for(r(y),s=0;!isdigit(y);r(y))s|=y==45;if(s)for(x=0;isdigit(y);r(y))x=x*10-(y^48);else for(x=0;isdigit(y);r(y))x=x*10+(y^48);return*this;}q&operator<<(char x){w(x);return*this;}q&operator<<(char*x){while(*x)w(*x++);return*this;}q&operator<<(const char*x){while(*x)w(*x++);return*this;}template<typename t>q&operator<<(t x){if(!x)w(48);else if(x<0)for(w(45);x;x/=10)*p++=48|-(x%10);else for(;x;x/=10)*p++=48|x%10;while(p!=h)w(*--p);return*this;}}qio;}using nqio::qio;
const int N=1e6+5;
int n,m,a[N],la,sq,ans;
vector<vector<int> > v;
vector<int> T;
int pos(int x){
int lst=-2e9;
rep(i,0,v.size()-1){
if(lst<x&&x<=v[i].back())return i;
lst=v[i].back();
}
return v.size()-1;
}
void ins(int x){
int p=pos(x);
v[p].insert(lower_bound(v[p].begin(),v[p].end(),x),x);
if(v[p].size()>sq*2){
vector<int> temp; temp.insert(temp.begin(),v[p].end()-sq,v[p].end());
v.insert(v.begin()+p+1,temp);
v[p].erase(v[p].end()-sq,v[p].end());
}
}
void era(int x){
int p=pos(x);
v[p].erase(lower_bound(v[p].begin(),v[p].end(),x));
if(!v[p].size())v.erase(v.begin()+p);
}
int rk(int x){
int p=pos(x),ans=0;
rep(i,0,p-1)ans+=v[i].size();
return ans+lower_bound(v[p].begin(),v[p].end(),x)-v[p].begin()+1;
}
int kth(int x){
rep(i,0,v.size()-1){
if(x-(int)v[i].size()>0)x-=v[i].size();
else return v[i][x-1];
}
return -1;
}
int pre(int x){return kth(rk(x)-1);}
int nxt(int x){return kth(rk(x+1));}
signed main(){
// freopen("1.in","r",stdin);
qio>>n>>m;sq=sqrt(n);
rep(i,1,n)qio>>a[i];
sort(a+1,a+n+1);
rep(i,1,n){
T.push_back(a[i]);
if(i%sq==0)v.push_back(T),T.clear();
}
if(T.size())v.push_back(T);
while(m--){
int op,x;qio>>op>>x;x^=la;
// qio<<op<<' '<<x<<'\n';
if(op==1)ins(x);
if(op==2)era(x);
if(op==3)la=rk(x);
if(op==4)la=kth(x);
if(op==5)la=pre(x);
if(op==6)la=nxt(x);
if(op>=3)ans^=la;
}
qio<<ans<<'\n';
return 0;
}
by qsceszthn @ 2021-06-05 17:27:45
就是#6 re,其他没问题
by 初雪_matt @ 2021-06-05 17:30:21
@qsceszthn 你这马蜂没谁了
by qsceszthn @ 2021-06-05 17:40:42
所以谁能告诉我为啥呀
by suolk @ 2021-07-27 06:04:19
数组开小啦
by spdarkle @ 2021-08-04 17:03:45
数组开5000000差不多