#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
const int mod = 1e9 + 7;
int cnt[7][1000];
int add[1001][1001], pref[1001][1001];
ll sum_pw[200010];
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int q; cin >> q;
vector<vector<int>> qrs(q, vector<int>(3));
for (int i = 0; i < q; i++) {
cin >> qrs[i][0] >> qrs[i][1] >> qrs[i][2];
qrs[i][0]--;
qrs[i][1]--;
}
for (int bit = 0; bit < 7; bit++) {
vector<int> delta(n + 1, 0);
for (int i = 0; i < q; i++) {
if ((qrs[i][2] >> bit) & 1) {
delta[qrs[i][0]]++;
delta[qrs[i][1] + 1]--;
}
}
int bal = 0;
for (int i = 0; i < n; i++) {
bal += delta[i];
cnt[bit][i] = bal;
}
}
for (int bit = 0; bit < 7; bit++) {
for (int bit2 = 0; bit2 < 7; bit2++) {
for (int i = 0; i < q; i++) {
if (((qrs[i][2] >> bit) & 1) && ((qrs[i][2] >> bit2) & 1)) {
add[qrs[i][0]][qrs[i][0]]++;
add[qrs[i][0]][qrs[i][1] + 1]--;
add[qrs[i][1] + 1][qrs[i][0]]--;
add[qrs[i][1] + 1][qrs[i][1] + 1]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
pref[i][j] = (i > 0 ? pref[i - 1][j] : 0) + (j > 0 ? pref[i][j - 1] : 0) - ((i > 0 && j > 0) ? pref[i - 1][j - 1] : 0) + add[i][j];
if (j >= i) {
int AD = q - (cnt[bit][i] + cnt[bit2][j] - pref[i][j]) + bit + bit2;
int C = (i + 1) * (n - j);
if (i != j)C*=2;
if (pref[i][j] == 0) {
if (cnt[bit][i] == 0 && ((a[i]>>bit)&1)==0)continue;
if (cnt[bit2][j]==0&&((a[j]>>bit2)&1)==0)continue;
int SS = max(0, cnt[bit][i] - 1) + max(0, cnt[bit2][j] - 1);
sum_pw[AD + SS] += C;
} else {
if (pref[i][j] == cnt[bit][i]) {
if (pref[i][j] == cnt[bit2][j]) {
if (((a[i]>>bit)&1)==((a[j]>>bit2)&1)) {
sum_pw[pref[i][j] - 1 + AD] += C;
}
} else {
sum_pw[cnt[bit2][j] - 2 + AD] += C;
}
} else {
if (pref[i][j] == cnt[bit2][j]) {
sum_pw[cnt[bit][i] - 2 + AD] += C;
} else {
sum_pw[AD + cnt[bit][i] + cnt[bit2][j] - pref[i][j] - 2] += C;
}
}
}
}
}
}
for (int i = 0; i < q; i++) {
if (((qrs[i][2] >> bit) & 1) && ((qrs[i][2] >> bit2) & 1)) {
add[qrs[i][0]][qrs[i][0]]--;
add[qrs[i][0]][qrs[i][1] + 1]++;
add[qrs[i][1] + 1][qrs[i][0]]++;
add[qrs[i][1] + 1][qrs[i][1] + 1]--;
}
}
}
}
ll ans = 0, pw = 1;
for (int i = 0; i < q + 20; i++) {
ans += ((sum_pw[i] % mod) * 1ll * pw) % mod;
ans %= mod;
pw *= 2;
pw %= mod;
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
3 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
10672 KB |
Output is correct |
2 |
Correct |
7 ms |
5208 KB |
Output is correct |
3 |
Correct |
3 ms |
4572 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
9300 KB |
Output is correct |
2 |
Correct |
178 ms |
9052 KB |
Output is correct |
3 |
Correct |
174 ms |
8876 KB |
Output is correct |
4 |
Correct |
177 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
3 ms |
4700 KB |
Output is correct |
5 |
Correct |
3 ms |
4700 KB |
Output is correct |
6 |
Correct |
4 ms |
4828 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
3 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4444 KB |
Output is correct |
13 |
Correct |
3 ms |
4444 KB |
Output is correct |
14 |
Correct |
3 ms |
4444 KB |
Output is correct |
15 |
Correct |
3 ms |
4564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
3 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
13 |
Correct |
3 ms |
4700 KB |
Output is correct |
14 |
Correct |
4 ms |
4828 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
3 ms |
4444 KB |
Output is correct |
17 |
Correct |
3 ms |
4444 KB |
Output is correct |
18 |
Correct |
3 ms |
4444 KB |
Output is correct |
19 |
Correct |
3 ms |
4564 KB |
Output is correct |
20 |
Correct |
110 ms |
15180 KB |
Output is correct |
21 |
Correct |
106 ms |
15196 KB |
Output is correct |
22 |
Correct |
81 ms |
15196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
3 ms |
4444 KB |
Output is correct |
7 |
Correct |
3 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
45 ms |
10672 KB |
Output is correct |
10 |
Correct |
7 ms |
5208 KB |
Output is correct |
11 |
Correct |
3 ms |
4572 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
184 ms |
9300 KB |
Output is correct |
14 |
Correct |
178 ms |
9052 KB |
Output is correct |
15 |
Correct |
174 ms |
8876 KB |
Output is correct |
16 |
Correct |
177 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
3 ms |
4700 KB |
Output is correct |
21 |
Correct |
3 ms |
4700 KB |
Output is correct |
22 |
Correct |
4 ms |
4828 KB |
Output is correct |
23 |
Correct |
3 ms |
4700 KB |
Output is correct |
24 |
Correct |
3 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
3 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4564 KB |
Output is correct |
28 |
Correct |
110 ms |
15180 KB |
Output is correct |
29 |
Correct |
106 ms |
15196 KB |
Output is correct |
30 |
Correct |
81 ms |
15196 KB |
Output is correct |
31 |
Correct |
237 ms |
16216 KB |
Output is correct |
32 |
Correct |
266 ms |
16216 KB |
Output is correct |
33 |
Correct |
220 ms |
15956 KB |
Output is correct |
34 |
Correct |
217 ms |
16000 KB |
Output is correct |
35 |
Correct |
232 ms |
15964 KB |
Output is correct |
36 |
Correct |
219 ms |
15952 KB |
Output is correct |