## 【2019HDU多校】HDU6579 线性基

### 传送门

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 233;
int f[maxn][33], pos[maxn][33];
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-f; ch=getchar();}
while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
char s[30];
inline void writeln(int x)
{
if (x<0) putchar('-'),x=-x;
if (!x) putchar('0'); else
{
int len=0;
while (x) s[++len]=x%10+'0',x/=10;
while (len) putchar(s[len--]);
}
putchar('\n');
}
{
for(int i = 30; i >= 0; --i) f[x][i] = f[x - 1][i], pos[x][i] = pos[x - 1][i];
int t = x;
for(int i = 30; i >= 0; --i)
{
if(v >> i)
{
if(!f[x][i])
{
f[x][i] = v, pos[x][i] = t;
break;
}
else
{
if(pos[x][i] < t)
swap(pos[x][i], t), swap(f[x][i], v);
v ^= f[x][i];
}
}
}
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int n, m;
scanf("%d%d", &n, &m);
int k;
for(int i = 1; i <= n; ++i) k = Read(), add(i, k);
int ans = 0;
int l, r;
for(int j = 1; j <= m; ++j)
{
int op; //scanf("%d", &op);
if(op == 0)
{
//scanf("%d%d", &l, &r);
l ^= ans, r ^= ans;
l = l % n + 1, r = r % n + 1;
if(l > r) swap(l, r);
ans = 0;
for(int i = 30; i >= 0; --i)
{
if(pos[r][i] >= l && ((ans ^ f[r][i]) > ans)) ans ^= f[r][i];
}
printf("%d\n", ans);
}
else
{
//scanf("%d", &k);