#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second
const int MOD = 1e9 + 7;
const int SIZE = 1005;
const int QSIZ = 1e5 + 5;
int n, q, ans;
int a[SIZE], pro[QSIZ];
int c1[SIZE], c2[SIZE], cnt[SIZE][SIZE];
tuple<int, int, int> ask[QSIZ];
inline pair<int, int> cal (int c) {
if (c == 0) return {0, 1};
return {pro[c - 1], pro[c - 1]};
}
void solve() {
cin >> n;
FOR (i, 1, n) cin >> a[i];
cin >> q;
FOR (i, 1, q) {
auto &[l, r, x] = ask[i];
cin >> l >> r >> x;
}
pro[0] = 1;
FOR (i, 1, max (q, 12)) pro[i] = (pro[i - 1] << 1) % MOD;
FOR (bi, 0, 6) FOR (bj, 0, 6) {
fill (c1, c1 + n + 1, 0);
fill (c2, c2 + n + 1, 0);
FOR (i, 1, n) fill (cnt[i], cnt[i] + n + 1, 0);
FOR (i, 1, q) {
auto [l, r, x] = ask[i];
if (x >> bi & 1) c1[l]++, c1[r + 1]--;
if (x >> bj & 1) c2[l]++, c2[r + 1]--;
if (x >> bi & 1 && x >> bj & 1) {
cnt[l][l]++, cnt[l][r + 1]--;
cnt[r + 1][l]--, cnt[r + 1][r + 1]++;
}
}
FOR (i, 1, n) {
c1[i] += c1[i - 1];
c2[i] += c2[i - 1];
FOR (j, 1, n) cnt[i][j] += cnt[i][j - 1];
FOR (j, 1, n) cnt[i][j] += cnt[i - 1][j];
}
FOR (i, 1, n) FOR (j, 1, n) {
auto [Odd, Even] = cal (cnt[i][j]);
auto [odd1, even1] = cal (c1[i] - cnt[i][j]);
auto [odd2, even2] = cal (c2[j] - cnt[i][j]);
if (a[i] >> bi & 1) swap (odd1, even1);
if (a[j] >> bj & 1) swap (odd2, even2);
int val = (1ll * Odd * even1 % MOD * even2 + 1ll * Even * odd1 % MOD * odd2) % MOD;
val = 1ll * val * pro[q - c1[i] - c2[j] + cnt[i][j]] % MOD;
val = 1ll * val * min (i, j) % MOD * (n - max (i, j) + 1) % MOD;
val = 1ll * pro[bi + bj] * val % MOD;
ans = (ans + val) % MOD;
}
}
cout << ans << '\n';
}
int main() {
Waimai;
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
724 KB |
Output is correct |
7 |
Correct |
11 ms |
736 KB |
Output is correct |
8 |
Correct |
11 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
2184 KB |
Output is correct |
2 |
Correct |
17 ms |
980 KB |
Output is correct |
3 |
Correct |
12 ms |
760 KB |
Output is correct |
4 |
Correct |
11 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1066 ms |
4272 KB |
Output is correct |
2 |
Correct |
1096 ms |
4300 KB |
Output is correct |
3 |
Correct |
1058 ms |
4300 KB |
Output is correct |
4 |
Correct |
1064 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
5 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
724 KB |
Output is correct |
7 |
Correct |
11 ms |
736 KB |
Output is correct |
8 |
Correct |
11 ms |
732 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
14 ms |
724 KB |
Output is correct |
13 |
Correct |
14 ms |
748 KB |
Output is correct |
14 |
Correct |
12 ms |
748 KB |
Output is correct |
15 |
Correct |
13 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
724 KB |
Output is correct |
7 |
Correct |
11 ms |
736 KB |
Output is correct |
8 |
Correct |
11 ms |
732 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
14 ms |
724 KB |
Output is correct |
17 |
Correct |
14 ms |
748 KB |
Output is correct |
18 |
Correct |
12 ms |
748 KB |
Output is correct |
19 |
Correct |
13 ms |
708 KB |
Output is correct |
20 |
Correct |
356 ms |
4912 KB |
Output is correct |
21 |
Correct |
344 ms |
4940 KB |
Output is correct |
22 |
Correct |
308 ms |
4812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
724 KB |
Output is correct |
7 |
Correct |
11 ms |
736 KB |
Output is correct |
8 |
Correct |
11 ms |
732 KB |
Output is correct |
9 |
Correct |
64 ms |
2184 KB |
Output is correct |
10 |
Correct |
17 ms |
980 KB |
Output is correct |
11 |
Correct |
12 ms |
760 KB |
Output is correct |
12 |
Correct |
11 ms |
708 KB |
Output is correct |
13 |
Correct |
1066 ms |
4272 KB |
Output is correct |
14 |
Correct |
1096 ms |
4300 KB |
Output is correct |
15 |
Correct |
1058 ms |
4300 KB |
Output is correct |
16 |
Correct |
1064 ms |
4300 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
4 ms |
468 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
24 |
Correct |
14 ms |
724 KB |
Output is correct |
25 |
Correct |
14 ms |
748 KB |
Output is correct |
26 |
Correct |
12 ms |
748 KB |
Output is correct |
27 |
Correct |
13 ms |
708 KB |
Output is correct |
28 |
Correct |
356 ms |
4912 KB |
Output is correct |
29 |
Correct |
344 ms |
4940 KB |
Output is correct |
30 |
Correct |
308 ms |
4812 KB |
Output is correct |
31 |
Correct |
1185 ms |
6900 KB |
Output is correct |
32 |
Correct |
1170 ms |
6984 KB |
Output is correct |
33 |
Correct |
1134 ms |
6816 KB |
Output is correct |
34 |
Correct |
1146 ms |
6844 KB |
Output is correct |
35 |
Correct |
1149 ms |
6704 KB |
Output is correct |
36 |
Correct |
1140 ms |
6688 KB |
Output is correct |