#pragma GCC optimize("O3", "unroll-loops") // "Ofast"
#pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt")
#include <bits/stdc++.h>
#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;
int n, q, l[N], r[N], x[N];
bool bit (int x, int i) {
return (x >> i & 1);
}
int add (int a, int b) {
a = (a + b) % mod;
return a;
}
int del (int a, int b) {
a = (a - b + mod) % mod;
return a;
}
int mul (int a, int b) {
a = (a % mod) * (b % mod) % mod;
return a;
}
void solve () {
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for (int i = 0; i < q; i++) cin >> l[i] >> r[i] >> x[i];
int ans = 0;
for (int mask = 0; mask < (1 << q); mask++) {
vt<int> xr(n + 2, 0), p(n + 1, 0);
for (int i = 0; i < q; i++) {
if (bit(mask, i)) xr[l[i]] ^= x[i], xr[r[i] + 1] ^= x[i];
}
for (int i = 1; i <= n; i++) xr[i] ^= xr[i - 1];
for (int i = 1; i <= n; i++) p[i] = p[i - 1] + (a[i] ^ xr[i]);
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) ans = add(ans, mul(p[j] - p[i - 1], p[j] - p[i - 1]));
}
}
cout << ans;
cout << '\n';
}
bool testcases = 0;
signed main() {
#ifdef ONLINE_JUDGE
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
cin.tie(0) -> sync_with_stdio(0);
int test = 1;
if (testcases) cin >> test;
for (int cs = 1; cs <= test; cs++) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
24 ms |
340 KB |
Output is correct |
8 |
Correct |
23 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
3388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2055 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2055 ms |
328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
24 ms |
340 KB |
Output is correct |
8 |
Correct |
23 ms |
340 KB |
Output is correct |
9 |
Execution timed out |
2055 ms |
328 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
24 ms |
340 KB |
Output is correct |
8 |
Correct |
23 ms |
340 KB |
Output is correct |
9 |
Execution timed out |
2055 ms |
328 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
24 ms |
340 KB |
Output is correct |
8 |
Correct |
23 ms |
340 KB |
Output is correct |
9 |
Incorrect |
16 ms |
3388 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |