题目大意
给你一个整数序列
{
a
n
}
\{a_n\}
{an},有两种操作,将执行
q
q
q次操作,第一种把
l
∼
r
l\sim r
l∼r的序列
c
o
p
y
copy
copy一份插到
r
r
r后,第二种询问
a
x
a_x
ax是什么,要求求出所有
2
2
2操作的异或和
n
,
q
≤
1
e
5
,
l
,
r
,
x
≤
n
n,q\le 1e5,l,r,x\le n
n,q≤1e5,l,r,x≤n
题解
第一种操作对后续询问的影响,如果
x
≤
r
x\le r
x≤r则不变,
x
>
r
x>r
x>r则
x
=
x
−
(
r
−
l
+
1
)
x=x-(r-l+1)
x=x−(r−l+1)
所以可以考虑从后往前进行操作,但是还是不好做
由于答案要求异或和,所以相同询问可以抵消,所以可以用
b
i
t
s
e
t
bitset
bitset维护,第一种操作也可以很轻松地用
b
i
t
s
e
t
bitset
bitset实现
code
#include<cstdio>
#include<bitset>
#include<iostream>
using namespace std;
void read(int &res)
{
res=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while('0'<=ch&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
}
const int N=1e5;
int n,q,a[N+10],opt[N+10],x[N+10],y[N+10];
bitset<N> dp,low,high;
int main()
{
int T;
read(T);
for(;T--;)
{
read(n),read(q);
for(int i=0;i<n;i++) read(a[i]);
for(int i=1;i<=q;i++)
{
read(opt[i]),read(x[i]);
if(opt[i]==1) read(y[i]);
x[i]--,y[i]--;
}
dp.reset();
for(int i=q;i>=1;i--)
{
if(opt[i]==1) high=dp>>y[i]+1,low=dp<<N-y[i]-1>>N-y[i]-1,dp=low^(high<<x[i]);
else dp.flip(x[i]);
}
int ans=0;
for(int i=0;i<n;i++) if(dp[i]) ans^=a[i];
printf("%d\n",ans);
}
return 0;
}