// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = (int)1e3 + 5;
const int MAXQ = (int)1e5 + 5;
const int MOD = (int)1e9 + 7;
int ways[2][2][2][2][2];
int seg[4][MAXN][MAXN], tot[4];
array<int, 3> que[MAXQ];
int pw[MAXQ];
int arr[MAXN];
int n, q, ans;
int addMod(int a, int b, int m = MOD) {
a += b;
if (m <= a) {
a -= m;
}
return a;
}
int mulMod(int a, int b, int m = MOD) {
return a * 1ll * b % m;
}
int binPow(int a, int b, int m = MOD) {
int ret = 1;
while (b > 0) {
if (b & 1) {
ret = mulMod(ret, a, m);
}
a = mulMod(a, a, m);
b >>= 1;
}
return ret;
}
int bit(int x, int p) {
return (x >> p) & 1;
}
void pre() {
pw[0] = 1;
for (int i = 1; i < MAXQ; ++i) {
pw[i] = mulMod(pw[i - 1], 2);
}
for (int bitA = 0; bitA < 2; ++bitA) {
for (int bitB = 0; bitB < 2; ++bitB) {
for (int x = 0; x < 2; ++x) {
for (int y = 0; y < 2; ++y) {
for (int z = 0; z < 2; ++z) {
int cnt = 0;
for (int xx = 0; xx <= x; ++xx) {
for (int yy = 0; yy <= y; ++yy) {
for (int zz = 0; zz <= z; ++zz) {
if ((bitA ^ xx ^ zz) == 1 && (bitB ^ yy ^ zz) == 1) {
++cnt;
}
}
}
}
ways[bitA][bitB][x][y][z] = cnt;
}
}
}
}
}
}
int calc(int p1, int p2) {
int ret = 0;
for (int i = 0; i < 4; ++i) {
for (int l = 1; l <= n; ++l) {
for (int r = 1; r <= n; ++r) {
seg[i][l][r] = 0;
}
}
tot[i] = 0;
}
for (int i = 1; i <= q; ++i) {
auto &[l, r, x] = que[i];
int msk = bit(x, p1) + (bit(x, p2) << 1);
seg[msk][l][r]++;
tot[msk]++;
}
for (int i = 1; i < 4; ++i) {
for (int l = 1; l <= n; ++l) {
int cur = 0;
for (int r = n; r; --r) {
cur += seg[i][l][r];
seg[i][l][r] = seg[i][l - 1][r] + cur;
}
}
}
for (int a = 1; a <= n; ++a) {
for (int b = 1; b <= n; ++b) {
array<int, 4> cnt = {0, 0, 0, 0}, tmp;
int bitA = bit(arr[a], p1);
int bitB = bit(arr[b], p2);
cnt[0] += tot[0];
// msk = 1
cnt[1] += seg[1][a][a];
cnt[0] += tot[1] - seg[1][a][a];
// msk = 2
cnt[2] += seg[2][b][b];
cnt[0] += tot[2] - seg[2][b][b];
for (int msk = 3; msk < 4; ++msk) {
tmp[0] = tot[msk];
tmp[1] = seg[msk][a][a];
tmp[2] = seg[msk][b][b];
tmp[3] = seg[msk][min(a, b)][max(a, b)];
tmp[1] -= tmp[3];
tmp[2] -= tmp[3];
tmp[0] -= tmp[1];
tmp[0] -= tmp[2];
tmp[0] -= tmp[3];
for (int msk2 = 0; msk2 < 4; ++msk2) {
cnt[msk2] += tmp[msk2];
}
}
int cur = ways[bitA][bitB][!!cnt[1]][!!cnt[2]][!!cnt[3]];
for (int i = 0; i < 4; ++i) {
cur = mulMod(cur, pw[max(0, cnt[i] - !!i)]);
}
cur = mulMod(cur, mulMod(min(a, b), n - max(a, b) + 1));
ret = addMod(ret, cur);
}
}
return ret;
}
void solve() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &arr[i]);
}
scanf("%d", &q);
for (int i = 1; i <= q; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
que[i] = {l, r, x};
}
for (int a = 0; a < 7; ++a) {
for (int b = a; b < 7; ++b) {
int cur = mulMod(calc(a, b), (1 << (a + b)));
if (b != a) {
cur = addMod(cur, cur);
}
ans = addMod(ans, cur);
}
}
printf("%d\n", ans);
}
int main() {
int tt = 1;
pre();
while (tt--) {
solve();
}
return 0;
}
Compilation message
xorsum.cpp: In function 'void solve()':
xorsum.cpp:170:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
xorsum.cpp:173:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
xorsum.cpp:176:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
xorsum.cpp:180:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &l, &r, &x);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
6 |
Correct |
18 ms |
2304 KB |
Output is correct |
7 |
Correct |
13 ms |
2304 KB |
Output is correct |
8 |
Correct |
13 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
3448 KB |
Output is correct |
2 |
Correct |
17 ms |
2432 KB |
Output is correct |
3 |
Correct |
13 ms |
2304 KB |
Output is correct |
4 |
Correct |
13 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1125 ms |
16632 KB |
Output is correct |
2 |
Correct |
1088 ms |
16632 KB |
Output is correct |
3 |
Correct |
1096 ms |
16524 KB |
Output is correct |
4 |
Correct |
1096 ms |
16512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1152 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
6 |
Correct |
18 ms |
2304 KB |
Output is correct |
7 |
Correct |
13 ms |
2304 KB |
Output is correct |
8 |
Correct |
13 ms |
2304 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
2 ms |
1152 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
18 ms |
2304 KB |
Output is correct |
13 |
Correct |
13 ms |
2304 KB |
Output is correct |
14 |
Correct |
15 ms |
2304 KB |
Output is correct |
15 |
Correct |
12 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
6 |
Correct |
18 ms |
2304 KB |
Output is correct |
7 |
Correct |
13 ms |
2304 KB |
Output is correct |
8 |
Correct |
13 ms |
2304 KB |
Output is correct |
9 |
Correct |
3 ms |
1152 KB |
Output is correct |
10 |
Correct |
2 ms |
1152 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
5 ms |
1280 KB |
Output is correct |
13 |
Correct |
5 ms |
1280 KB |
Output is correct |
14 |
Correct |
5 ms |
1280 KB |
Output is correct |
15 |
Correct |
5 ms |
1280 KB |
Output is correct |
16 |
Correct |
18 ms |
2304 KB |
Output is correct |
17 |
Correct |
13 ms |
2304 KB |
Output is correct |
18 |
Correct |
15 ms |
2304 KB |
Output is correct |
19 |
Correct |
12 ms |
2304 KB |
Output is correct |
20 |
Correct |
357 ms |
9940 KB |
Output is correct |
21 |
Correct |
348 ms |
9720 KB |
Output is correct |
22 |
Correct |
355 ms |
9720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
768 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
3 |
Correct |
2 ms |
896 KB |
Output is correct |
4 |
Correct |
2 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
6 |
Correct |
18 ms |
2304 KB |
Output is correct |
7 |
Correct |
13 ms |
2304 KB |
Output is correct |
8 |
Correct |
13 ms |
2304 KB |
Output is correct |
9 |
Correct |
61 ms |
3448 KB |
Output is correct |
10 |
Correct |
17 ms |
2432 KB |
Output is correct |
11 |
Correct |
13 ms |
2304 KB |
Output is correct |
12 |
Correct |
13 ms |
2304 KB |
Output is correct |
13 |
Correct |
1125 ms |
16632 KB |
Output is correct |
14 |
Correct |
1088 ms |
16632 KB |
Output is correct |
15 |
Correct |
1096 ms |
16524 KB |
Output is correct |
16 |
Correct |
1096 ms |
16512 KB |
Output is correct |
17 |
Correct |
3 ms |
1152 KB |
Output is correct |
18 |
Correct |
2 ms |
1152 KB |
Output is correct |
19 |
Correct |
2 ms |
1152 KB |
Output is correct |
20 |
Correct |
5 ms |
1280 KB |
Output is correct |
21 |
Correct |
5 ms |
1280 KB |
Output is correct |
22 |
Correct |
5 ms |
1280 KB |
Output is correct |
23 |
Correct |
5 ms |
1280 KB |
Output is correct |
24 |
Correct |
18 ms |
2304 KB |
Output is correct |
25 |
Correct |
13 ms |
2304 KB |
Output is correct |
26 |
Correct |
15 ms |
2304 KB |
Output is correct |
27 |
Correct |
12 ms |
2304 KB |
Output is correct |
28 |
Correct |
357 ms |
9940 KB |
Output is correct |
29 |
Correct |
348 ms |
9720 KB |
Output is correct |
30 |
Correct |
355 ms |
9720 KB |
Output is correct |
31 |
Correct |
1194 ms |
18776 KB |
Output is correct |
32 |
Correct |
1151 ms |
18776 KB |
Output is correct |
33 |
Correct |
1196 ms |
18680 KB |
Output is correct |
34 |
Correct |
1244 ms |
18588 KB |
Output is correct |
35 |
Correct |
1230 ms |
18680 KB |
Output is correct |
36 |
Correct |
1272 ms |
18560 KB |
Output is correct |