Untitled

public
yousefkarem91 Aug 12, 2024 Never 59
Clone
C++ paste1.cpp 179 lines (173 loc) | 4.19 KB
1
#include<bits/stdc++.h>
2
using namespace std;
3
#define ll long long
4
#define all(d) d.begin(),d.end()
5
#define test int t;cin>>t;while(t--)
6
#define ones(n) __builtin_popcount(n)
7
#define last(n) ____builtin_clz(len)
8
const int dx8[8] = {1, 0, -1, 0,-1,-1,1,1};
9
const int dy8[8] = {0, 1, 0, -1, -1, 1, -1, 1};
10
int dx[] = {+0, +0, +1, -1};
11
int dy[] = {+1, -1, +0, +0};
12
char di[]={'R','L','D','U'};
13
void JOO() {
14
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
15
#ifndef ONLINE_JUDGE
16
freopen("input.txt", "r", stdin);
17
freopen("output.txt", "w", stdout);
18
#endif
19
}
20
const int N=2e5+5,M=1e3,LOG=20,inf=0x3f3f3f3f;
21
int MOD=1e9+7;
22
ll infLL=0x3f3f3f3f3f3f3f3f;
23
struct Basis{
24
vector<ll>basis;
25
int LOG,sz;
26
Basis(int log = 30){
27
LOG = log;
28
sz = 0;
29
basis.resize(LOG);
30
}
31
bool insert(ll x){
32
for (int i = LOG - 1; i >= 0; --i) {
33
if(x >> i & 1 ^ 1)
34
continue;
35
if(basis[i]){
36
x ^= basis[i];
37
}
38
else{
39
basis[i] = x;
40
sz++;
41
return true;
42
}
43
}
44
return false;
45
}
46
ll getMax(ll x = 0){
47
ll ret = x;
48
for (int i = LOG - 1; i >= 0; --i) {
49
ret = max(ret,ret ^ basis[i]);
50
}
51
return ret;
52
}
53
};
54
struct item
55
{
56
int lz;
57
Basis basis;
58
item()
59
{
60
lz=INT_MAX;
61
}
62
item(int v)
63
{
64
lz=INT_MAX;
65
basis.insert(v);
66
}
67
};
68
struct segTree {
69
vector<item> seg;
70
int sz = 1,n,NO_OP = INT_MAX;
71
segTree(int nn){
72
n = nn;
73
while (sz < nn)
74
sz *= 2;
75
seg.assign(2 * sz , item());
76
}
77
78
item merge(item seg1, item seg2) {
79
item ret=seg1;
80
for(int x:seg2.basis.basis)
81
{
82
if(x)
83
ret.basis.insert(x);
84
}
85
return ret;
86
}
87
88
void propagate(int x, int lx, int rx) {
89
if (seg[x].lz != NO_OP) {
90
Basis tmp;
91
for(int curr:seg[x].basis.basis)
92
{
93
tmp.insert(curr&seg[x].lz);
94
}
95
seg[x].basis = tmp;
96
int lf = 2*x+1,rt = 2*x+2;
97
if (lx != rx) {
98
seg[lf].lz &= seg[x].lz;
99
seg[rt].lz &= seg[x].lz;
100
}
101
seg[x].lz = NO_OP;
102
}
103
}
104
105
void update(int l,int r, ll val, int x, int lx, int rx,int op) {
106
propagate(x, lx, rx);
107
if (l > rx || r < lx)
108
return;
109
if (l <= lx && r >= rx) {
110
if(op==1)
111
seg[x].lz &= val;
112
else
113
seg[x]=item(val);
114
propagate(x, lx, rx);
115
return;
116
}
117
int mid = (lx + rx) / 2,lf = 2*x+1,rt= 2*x+2;
118
update(l, r, val, lf, lx, mid,op);
119
update(l, r, val, rt, mid + 1, rx,op);
120
seg[x] = merge(seg[lf] , seg[rt]);
121
}
122
//update[l,r]
123
void update(int l,int r, ll val,int op) {
124
update(l, r, val, 0, 0, sz-1,op);
125
}
126
127
item query(int l, int r, int x, int lx, int rx) {
128
propagate(x, lx, rx);
129
if (l <= lx && r >= rx)
130
return seg[x];
131
if (l > rx || r < lx)
132
return item();
133
134
int mid = (lx + rx) / 2,lf = 2*x+1,rt = 2*x+2;
135
136
return merge(query(l, r, lf, lx, mid) , query(l, r, rt, mid + 1, rx));
137
}
138
//query[l,r]
139
ll query(int l, int r) {
140
return query(l, r, 0, 0, sz-1).basis.getMax();
141
}
142
};
143
void solve()
144
{
145
int n,q;cin>>n>>q;
146
vector<int>v(n);
147
segTree seg(n);
148
for (int i = 0; i < n; ++i) {
149
cin>>v[i];
150
seg.update(i,i,v[i],2);
151
}
152
while(q--)
153
{
154
int op,x,y;
155
cin>>op>>x>>y;
156
if(op==3)
157
{
158
cout<<seg.query(x-1,y-1)<<'\n';
159
}
160
else if(op==2)
161
{
162
seg.update(x-1,x-1,y,op);
163
}
164
else
165
{
166
int val;cin>>val;
167
seg.update(x-1,y-1,val,op);
168
}
169
}
170
}
171
signed main() {
172
JOO();
173
// int cnt=1;
174
test
175
{
176
// cout << "Case " << "#" << cnt++ << ": ";
177
solve();
178
}
179
}