#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int a[n + 1], b[501][501] {}, c[n + 1][32] {}, d[n + 1][32] {};
for(int i = 1; i <= n; i++) {
cin >> a[i];
int x = a[i], y = 31;
while(x > 0) {
c[i][y] = x % 2;
x /= 2;
y--;
}
}
for(int i = 1; i <= n; i++) {
for(int j = 0; j < 32; j++) {
d[i][j] = d[i - 1][j] + c[i][j];
}
}
if(n <= 500) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
for(int k = i; k <= min(i + j - 1, n); k++) {
b[i][j] = (b[i][j] ^ a[k]);
}
}
}
}
if(n <= 100) {
while(q--) {
int t, l, r;
cin >> t >> l >> r;
if(t == 1) {
a[l] = r;
} else {
int S = a[l];
for(int i = l + 1; i <= r; i++) {
S = (S ^ a[i]);
}
for(int i = 2; i <= r - l + 1; i++) {
for(int j = l; j <= r - i + 1; j++) {
int A = 0;
for(int k = j; k <= j + i - 1; k++) {
A = (A ^ a[k]);
}
S = (S ^ A);
}
}
cout << S << '\n';
}
}
} else if(n <= 500) {
while(q--) {
int t, l, r;
cin >> t >> l >> r;
int S = 0;
for(int i = 1; i <= r - l + 1; i++) {
for(int j = l; j <= r - i + 1; j++) {
S = (S ^ b[j][i]);
}
}
cout << S << '\n';
}
} else {
while(q--) {
int t, l, r;
cin >> t >> l >> r;
int A[32] {};
int x = r - l + 1;
for(int i = 0; i < 32; i++) {
A[i] = (x * (d[r][i] - d[l - 1][i])) % 2;
}
for(int i = 0; i < 32; i++) {
A[i] += (((r - l) * 2 - x) * (d[r - 1][i] - d[l][i]));
A[i] %= 2;
}
int S = 0;
for(int i = 0; i < 32; i++) {
S += A[i] * (1 << (31 - i));
}
cout << S << '\n';
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
4 ms |
1372 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1372 KB |
Output is correct |
2 |
Correct |
21 ms |
1556 KB |
Output is correct |
3 |
Correct |
22 ms |
1372 KB |
Output is correct |
4 |
Correct |
40 ms |
1372 KB |
Output is correct |
5 |
Correct |
39 ms |
1560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
4 ms |
1372 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
22 ms |
1372 KB |
Output is correct |
7 |
Correct |
21 ms |
1556 KB |
Output is correct |
8 |
Correct |
22 ms |
1372 KB |
Output is correct |
9 |
Correct |
40 ms |
1372 KB |
Output is correct |
10 |
Correct |
39 ms |
1560 KB |
Output is correct |
11 |
Runtime error |
4 ms |
4956 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
53416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1372 KB |
Output is correct |
2 |
Correct |
2 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
4 ms |
1372 KB |
Output is correct |
5 |
Correct |
4 ms |
1372 KB |
Output is correct |
6 |
Correct |
22 ms |
1372 KB |
Output is correct |
7 |
Correct |
21 ms |
1556 KB |
Output is correct |
8 |
Correct |
22 ms |
1372 KB |
Output is correct |
9 |
Correct |
40 ms |
1372 KB |
Output is correct |
10 |
Correct |
39 ms |
1560 KB |
Output is correct |
11 |
Runtime error |
4 ms |
4956 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |