#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1003, K = 7, M = 1e9 + 7;
int one[K][N], both[K][K][N][N], in[N], pw2[100005];
signed main()
{
IO_OP;
pw2[0] = 1;
for(int i = 1; i < 100005; i++)
pw2[i] = pw2[i - 1] * 2 % M;
int n, q;
cin >> n;
for(int i = 0; i < n; i++) cin >> in[i];
cin >> q;
for(int i = 0; i < q; i++) {
int l, r, x;
cin >> l >> r >> x;
l--, r--;
for(int a = 0; a < K; a++) if(x >> a & 1)
one[a][l]++, one[a][r + 1]--;
for(int a = 0; a < K; a++) if(x >> a & 1)
for(int b = 0; b < K; b++) if(x >> b & 1)
both[a][b][l][r]++;
}
for(int a = 0; a < K; a++)
for(int i = 1; i < n; i++)
one[a][i] += one[a][i - 1];
for(int a = 0; a < K; a++)
for(int b = 0; b < K; b++)
for(int len = n; len >= 2; len--)
for(int i = 0; i + len - 1 < n; i++) {
int j = i + len - 1, t = both[a][b][i][j];
both[a][b][i][j - 1] += t;
both[a][b][i + 1][j] += t;
both[a][b][i + 1][j - 1] -= t;
}
int ans = 0;
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++) {
int occ = (i + 1) * (n - j);
if(i != j) occ *= 2;
for(int a = 0; a < K; a++)
for(int b = 0; b < K; b++) {
int mul = occ << (a + b);
int c11 = both[a][b][i][j], c10 = one[a][i] - c11, c01 = one[b][j] - c11, c00 = q - c11 - c01 - c10;
int b0 = in[i] >> a & 1, b1 = in[j] >> b & 1;
int res00 = 0, res11 = 0;
if(c01 && c10) {
res00 = res11 = pw2[c01 + c10 - 2];
} else if(!c01 && !c10) {
if(b0 == 0 && b1 == 0) res00 = 1;
else if(b0 == 1 && b1 == 1) res11 = 1;
} else if(c01) {
if(((b0 ^ 0) == 0 && (b1 ^ 1) == 0) || ((b0 ^ 0) == 0 && (b1 ^ 0) == 0))
res00 = pw2[c01 - 1];
if(((b0 ^ 0) == 1 && (b1 ^ 1) == 1) || ((b0 ^ 0) == 1 && (b1 ^ 0) == 1))
res11 = pw2[c01 - 1];
} else if(c10){
if(((b0 ^ 1) == 0 && (b1 ^ 0) == 0) || ((b0 ^ 0) == 0 && (b1 ^ 0) == 0))
res00 = pw2[c10 - 1];
if(((b0 ^ 1) == 1 && (b1 ^ 0) == 1) || ((b0 ^ 0) == 1 && (b1 ^ 0) == 1))
res11 = pw2[c10 - 1];
} else throw;
int res = 0;
if(c11) res = (ll)(res00 + res11) % M * pw2[c11 - 1] % M;
else res = res11;
res = (ll) res * pw2[c00] % M * mul % M;
ans = (ans + res) % M;
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1900 KB |
Output is correct |
3 |
Correct |
3 ms |
2924 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1900 KB |
Output is correct |
3 |
Correct |
3 ms |
2924 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
6 |
Correct |
15 ms |
20204 KB |
Output is correct |
7 |
Correct |
14 ms |
20204 KB |
Output is correct |
8 |
Correct |
15 ms |
20204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
20204 KB |
Output is correct |
2 |
Correct |
18 ms |
20332 KB |
Output is correct |
3 |
Correct |
15 ms |
20204 KB |
Output is correct |
4 |
Correct |
15 ms |
20204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
571 ms |
193376 KB |
Output is correct |
2 |
Correct |
562 ms |
193260 KB |
Output is correct |
3 |
Correct |
529 ms |
193260 KB |
Output is correct |
4 |
Correct |
527 ms |
193260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6764 KB |
Output is correct |
2 |
Correct |
4 ms |
6764 KB |
Output is correct |
3 |
Correct |
4 ms |
6764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6764 KB |
Output is correct |
2 |
Correct |
4 ms |
6764 KB |
Output is correct |
3 |
Correct |
4 ms |
6764 KB |
Output is correct |
4 |
Correct |
6 ms |
6764 KB |
Output is correct |
5 |
Correct |
6 ms |
6764 KB |
Output is correct |
6 |
Correct |
6 ms |
6764 KB |
Output is correct |
7 |
Correct |
6 ms |
6764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1900 KB |
Output is correct |
3 |
Correct |
3 ms |
2924 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
6 |
Correct |
15 ms |
20204 KB |
Output is correct |
7 |
Correct |
14 ms |
20204 KB |
Output is correct |
8 |
Correct |
15 ms |
20204 KB |
Output is correct |
9 |
Correct |
5 ms |
6764 KB |
Output is correct |
10 |
Correct |
4 ms |
6764 KB |
Output is correct |
11 |
Correct |
4 ms |
6764 KB |
Output is correct |
12 |
Correct |
16 ms |
20204 KB |
Output is correct |
13 |
Correct |
17 ms |
20204 KB |
Output is correct |
14 |
Correct |
15 ms |
20204 KB |
Output is correct |
15 |
Correct |
17 ms |
20204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1900 KB |
Output is correct |
3 |
Correct |
3 ms |
2924 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
6 |
Correct |
15 ms |
20204 KB |
Output is correct |
7 |
Correct |
14 ms |
20204 KB |
Output is correct |
8 |
Correct |
15 ms |
20204 KB |
Output is correct |
9 |
Correct |
5 ms |
6764 KB |
Output is correct |
10 |
Correct |
4 ms |
6764 KB |
Output is correct |
11 |
Correct |
4 ms |
6764 KB |
Output is correct |
12 |
Correct |
6 ms |
6764 KB |
Output is correct |
13 |
Correct |
6 ms |
6764 KB |
Output is correct |
14 |
Correct |
6 ms |
6764 KB |
Output is correct |
15 |
Correct |
6 ms |
6764 KB |
Output is correct |
16 |
Correct |
16 ms |
20204 KB |
Output is correct |
17 |
Correct |
17 ms |
20204 KB |
Output is correct |
18 |
Correct |
15 ms |
20204 KB |
Output is correct |
19 |
Correct |
17 ms |
20204 KB |
Output is correct |
20 |
Correct |
257 ms |
98284 KB |
Output is correct |
21 |
Correct |
183 ms |
98284 KB |
Output is correct |
22 |
Correct |
220 ms |
98156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1388 KB |
Output is correct |
2 |
Correct |
2 ms |
1900 KB |
Output is correct |
3 |
Correct |
3 ms |
2924 KB |
Output is correct |
4 |
Correct |
2 ms |
2924 KB |
Output is correct |
5 |
Correct |
2 ms |
2924 KB |
Output is correct |
6 |
Correct |
15 ms |
20204 KB |
Output is correct |
7 |
Correct |
14 ms |
20204 KB |
Output is correct |
8 |
Correct |
15 ms |
20204 KB |
Output is correct |
9 |
Correct |
46 ms |
20204 KB |
Output is correct |
10 |
Correct |
18 ms |
20332 KB |
Output is correct |
11 |
Correct |
15 ms |
20204 KB |
Output is correct |
12 |
Correct |
15 ms |
20204 KB |
Output is correct |
13 |
Correct |
571 ms |
193376 KB |
Output is correct |
14 |
Correct |
562 ms |
193260 KB |
Output is correct |
15 |
Correct |
529 ms |
193260 KB |
Output is correct |
16 |
Correct |
527 ms |
193260 KB |
Output is correct |
17 |
Correct |
5 ms |
6764 KB |
Output is correct |
18 |
Correct |
4 ms |
6764 KB |
Output is correct |
19 |
Correct |
4 ms |
6764 KB |
Output is correct |
20 |
Correct |
6 ms |
6764 KB |
Output is correct |
21 |
Correct |
6 ms |
6764 KB |
Output is correct |
22 |
Correct |
6 ms |
6764 KB |
Output is correct |
23 |
Correct |
6 ms |
6764 KB |
Output is correct |
24 |
Correct |
16 ms |
20204 KB |
Output is correct |
25 |
Correct |
17 ms |
20204 KB |
Output is correct |
26 |
Correct |
15 ms |
20204 KB |
Output is correct |
27 |
Correct |
17 ms |
20204 KB |
Output is correct |
28 |
Correct |
257 ms |
98284 KB |
Output is correct |
29 |
Correct |
183 ms |
98284 KB |
Output is correct |
30 |
Correct |
220 ms |
98156 KB |
Output is correct |
31 |
Correct |
752 ms |
194412 KB |
Output is correct |
32 |
Correct |
526 ms |
194412 KB |
Output is correct |
33 |
Correct |
713 ms |
194284 KB |
Output is correct |
34 |
Correct |
683 ms |
194284 KB |
Output is correct |
35 |
Correct |
695 ms |
194156 KB |
Output is correct |
36 |
Correct |
684 ms |
194156 KB |
Output is correct |