Time limit 4000 ms
Memory limit 262144 kB
OS Windows
Source 2019 Multi-University Training Contest 1
Chinese 题意
A sequence supports two modes of operation -
- Insert a number in the back, and the sequence length is increased by one
- Asked an interval of maximum XOR
Forced online.
Problem-solving ideas
Basic is a question on Ivan and Burgers it. I have a question on the use of the solution is online. Although still not proven.
- [X] codeforces 1100F of Ivan and Burgers simple XOR maximum interrogation zone
- [X] 6579 HDU Operation plurality of operations insertion end of the data, as well as by force
- [] BZOJ 4184 Shallot this title more than the operating insertions and deletions. Actually measure what the local authority title ...... forget.
- [] UVALive 8514 XOR 2017ICPC Xi'an a question, almost all operations
Source
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAXN=1e6+5;
const int wide=31;
int T;
int n,m;
int p[MAXN][wide+2],pos[MAXN][wide+2];
void insert(int loc,int val)//location value
{
for(int i=wide;~i;i--)
{
p[loc][i]=p[loc-1][i];
pos[loc][i]=pos[loc-1][i];
}
int temp=loc;
for(int i=wide;~i;i--)
{
if((val>>i)&1)
{
if(!p[loc][i])
{
p[loc][i]=val;
pos[loc][i]=temp;
return;
}
if(pos[loc][i]<temp)//还是不太懂
{
std::swap(pos[loc][i],temp);
std::swap(p[loc][i],val);
}
val^=p[loc][i];
}
}
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(pos,0,sizeof(int)*(wide+2)*(n+2));
memset(p,0,sizeof(int)*(wide+2)*(n+2));
for(int i=1,v;i<=n;i++)
{
scanf("%d",&v);
insert(i,v);
}
int lastans=0;
while(m--)
{
int opt,l,r;
scanf("%d",&opt);
if(opt)
{
scanf("%d",&l);
l^=lastans;
insert(++n,l);
}
else
{
scanf("%d%d",&l,&r);
l=(l^lastans)%n+1;
r=(r^lastans)%n+1;
if(l>r) std::swap(l,r);
int ans=0;
for(int i=wide;~i;i--)
{
if((ans^p[r][i])>ans&&pos[r][i]>=l)
ans^=p[r][i];
}
printf("%d\n",lastans=ans);
}
}
}
return 0;
}