Operation
思路
只要套上前缀线性基的板子然后按照题意模拟即可,前缀线性基模板题了。
代码
/*Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>#define mp make_pair
#define pb push_back
#define endl '\n'
#define mid (l + r >> 1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define ls rt << 1
#define rs rt << 1 | 1using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;const double pi = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;inline ll read() {ll f = 1, x = 0;char c = getchar();while(c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while(c >= '0' && c <= '9') {x = (x << 1) + (x << 3) + (c ^ 48);c = getchar();}return f * x;
}const int N = 5e5 + 10;struct PrefixLinearBasis {int base[N][32], pos[N][32], num, n = 30;void init() {for(int i = 0; i < N; i++) {memset(base[i], 0, sizeof base[i]);memset(pos[i], 0, sizeof pos[i]);num = 0;}}void add(int x) {num++;for(int i = 0; i <= n; i++) {base[num][i] = base[num - 1][i];pos[num][i] = pos[num - 1][i];}int p = num;for(int i = n; ~i; i--) {if(x >> i & 1) {if(base[num][i] == 0) {base[num][i] = x;pos[num][i] = p;return ;}if(pos[num][i] < p) {swap(pos[num][i], p);swap(base[num][i], x);}x ^= base[num][i];}}}int query_max(int l, int r) {ll ans = 0;for(int i = n; ~i; i--) {if(pos[r][i] < l) continue;if((ans ^ base[r][i]) > ans) {ans ^= base[r][i];}}return ans;}int query_min(int l, int r) {for(int i = 0; i <= n; i++) {if(pos[r][i] < l) continue;if(base[r][i]) return base[r][i];}}
}ans;int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int T = read();while(T--) {int n = read(), m = read(), last_ans = 0;ans.init();for(int i = 1; i <= n; i++) {int x = read();ans.add(x);}for(int i = 1; i <= m; i++) {int op = read();if(op) {int x = read();x ^= last_ans;n++;ans.add(x);}else {int l = (read() ^ last_ans) % n + 1, r = (read() ^ last_ans) % n + 1;if(l > r) swap(l, r);last_ans = ans.query_max(l, r);printf("%d\n", last_ans);}}}return 0;
}