#include <iostream>
#include <vector>
#include <map>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int MAXN = 1008;
const ll MOD = 1000000007;
const int MAXVAL = 128;
const int HEY = MAXVAL * 3;
int a[MAXN];
void updt(bitset<MAXVAL>& bs, int t) {
if (bs[bs._Find_first() ^ t])
return;
if (bs.count() == 64) {
for (int i = 0; i < MAXVAL; ++i)
bs[i] = 1;
return;
}
int sz = bs.count();
for (int i = bs._Find_first(); i < MAXVAL; ++i) {
if (bs[i])
bs[i ^ t] = bs[i];
}
}
ll pw(ll a, ll m) {
if (!m)
return 1;
a %= MOD;
if (m % 2)
return a * pw(a, m - 1) % MOD;
return pw(a * a, m / 2);
}
bool in(pair<int, int> sg, int i) {
return sg.first <= i && i < sg.second;
}
vector<pair<int, int>> events[MAXN];
int change_ij[MAXN][MAXVAL];
int change_i[MAXN][MAXVAL];
int change_j[MAXN][MAXVAL];
struct sixple {
ull first;
ull second;
ull third;
ull fourth;
ull fifth;
ull sixth;
bool operator<(sixple& s) {
if (first != s.first)
return first < s.first;
if (second != s.second)
return second < s.second;
if (third != s.third)
return third < s.third;
if (fourth != s.fourth)
return fourth < s.fourth;
if (fifth != s.fifth)
return fifth < s.fifth;
return sixth < s.sixth;
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int l, r, x;
cin >> l >> r >> x;
--l;
events[l].push_back({r, x});
events[r].push_back({l, x});
++change_j[l][x];
--change_j[r][x];
}
ll ans = 0;
vector<int> genij0(MAXVAL, 0);
bitset<MAXVAL> genbsij0;
for (int i = 0; i < n; ++i) {
for (auto [e, x] : events[i]) {
if (e < i)
genbsij0[x] = --genij0[x];
else {
genbsij0[x] = ++genij0[x];
--change_ij[e][x];
++change_j[e][x];
++change_i[e][x];
}
}
vector<int> geni(MAXVAL);
vector<int> genj(MAXVAL);
vector<int> genij = genij0;
for (int j = i; j < n; ++j) {
if (j > i) {
for (int x = 0; x < 128; ++x) {
genij[x] += change_ij[j][x];
geni[x] += change_i[j][x];
genj[x] += change_j[j][x];
}
}
bitset<MAXVAL> bsi;
bitset<MAXVAL> bsj;
bitset<MAXVAL> bsij;
bsi[a[i]] = bsj[a[j]] = bsij[0] = 1;
for (int xi = 0; xi < MAXVAL; ++xi) {
if (geni[xi])
updt(bsi, xi);
if (bsi.count() == 128)
break;
}
for (int xj = 0; xj < MAXVAL; ++xj) {
if (genj[xj])
updt(bsj, xj);
if (bsj.count() == 128)
break;
}
if (n > 500 && q > 500)
continue;
for (int xij = 0; xij < MAXVAL; ++xij) {
if (genij[xij])
updt(bsij, xij);
if (bsij.count() == 128)
break;
}
ll addans = 0;
if (bsij.count() == 128 && (bsi.count() == 128 || bsj.count() == 128)) {
if (bsi.count() == 128) {
addans += 64ll * 127 * 64 * 127 * bsj.count();
} else {
addans += 64ll * 127 * 64 * 127 * bsi.count();
}
} else {
vector<int> xj_from_xij(MAXVAL);
for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
if (bsj.count() == 128) {
xj_from_xij[xij] = 64 * 127;
} else {
for (int xj = bsj._Find_first(); xj < MAXVAL; xj = bsj._Find_next(xj)) {
xj_from_xij[xij] += xj ^ xij;
}
}
}
for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
if (bsi.count() == 128) {
addans += xj_from_xij[xij] * 64 * 127;
} else {
for (int xi = bsi._Find_first(); xi < MAXVAL; xi = bsi._Find_next(xi)) {
addans += xj_from_xij[xij] * (xi ^ xij);
}
}
addans %= MOD;
}
}
if (i != j) {
addans *= 2;
}
addans *= (i + 1) * (n - j);
addans %= MOD;
addans *= pw(2, q);
addans %= MOD;
//cout << bsi.count() << ' ' << bsj.count() << ' ' << bsij.count() << endl;
addans *= pw(bsi.count() * bsj.count() * bsij.count(), MOD - 2);
ans += addans;
ans %= MOD;
//cout << i << ' ' << j << ": " << ans - ans0 << endl;
}
}
cout << ans << endl;
}
Compilation message
xorsum.cpp: In function 'void updt(std::bitset<128>&, int)':
xorsum.cpp:24:9: warning: unused variable 'sz' [-Wunused-variable]
24 | int sz = bs.count();
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 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 |
1 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 |
19 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
380 KB |
Output is correct |
8 |
Correct |
15 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
2484 KB |
Output is correct |
2 |
Correct |
25 ms |
728 KB |
Output is correct |
3 |
Correct |
21 ms |
476 KB |
Output is correct |
4 |
Correct |
19 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1391 ms |
1756 KB |
Output is correct |
2 |
Correct |
1293 ms |
1892 KB |
Output is correct |
3 |
Correct |
1283 ms |
1448 KB |
Output is correct |
4 |
Correct |
1264 ms |
1000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
572 KB |
Output is correct |
5 |
Correct |
8 ms |
468 KB |
Output is correct |
6 |
Correct |
8 ms |
468 KB |
Output is correct |
7 |
Correct |
9 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 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 |
19 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
380 KB |
Output is correct |
8 |
Correct |
15 ms |
436 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
32 ms |
468 KB |
Output is correct |
13 |
Correct |
33 ms |
468 KB |
Output is correct |
14 |
Correct |
23 ms |
412 KB |
Output is correct |
15 |
Correct |
63 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 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 |
19 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
380 KB |
Output is correct |
8 |
Correct |
15 ms |
436 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
3 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
572 KB |
Output is correct |
13 |
Correct |
8 ms |
468 KB |
Output is correct |
14 |
Correct |
8 ms |
468 KB |
Output is correct |
15 |
Correct |
9 ms |
596 KB |
Output is correct |
16 |
Correct |
32 ms |
468 KB |
Output is correct |
17 |
Correct |
33 ms |
468 KB |
Output is correct |
18 |
Correct |
23 ms |
412 KB |
Output is correct |
19 |
Correct |
63 ms |
500 KB |
Output is correct |
20 |
Correct |
695 ms |
3252 KB |
Output is correct |
21 |
Correct |
574 ms |
3300 KB |
Output is correct |
22 |
Correct |
603 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 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 |
19 ms |
340 KB |
Output is correct |
7 |
Correct |
14 ms |
380 KB |
Output is correct |
8 |
Correct |
15 ms |
436 KB |
Output is correct |
9 |
Correct |
43 ms |
2484 KB |
Output is correct |
10 |
Correct |
25 ms |
728 KB |
Output is correct |
11 |
Correct |
21 ms |
476 KB |
Output is correct |
12 |
Correct |
19 ms |
432 KB |
Output is correct |
13 |
Correct |
1391 ms |
1756 KB |
Output is correct |
14 |
Correct |
1293 ms |
1892 KB |
Output is correct |
15 |
Correct |
1283 ms |
1448 KB |
Output is correct |
16 |
Correct |
1264 ms |
1000 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
8 ms |
572 KB |
Output is correct |
21 |
Correct |
8 ms |
468 KB |
Output is correct |
22 |
Correct |
8 ms |
468 KB |
Output is correct |
23 |
Correct |
9 ms |
596 KB |
Output is correct |
24 |
Correct |
32 ms |
468 KB |
Output is correct |
25 |
Correct |
33 ms |
468 KB |
Output is correct |
26 |
Correct |
23 ms |
412 KB |
Output is correct |
27 |
Correct |
63 ms |
500 KB |
Output is correct |
28 |
Correct |
695 ms |
3252 KB |
Output is correct |
29 |
Correct |
574 ms |
3300 KB |
Output is correct |
30 |
Correct |
603 ms |
3284 KB |
Output is correct |
31 |
Incorrect |
1629 ms |
4096 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |