This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
const ll MOD = 1e9 + 7;
int a[N], b[N], c[N], l[N], r[N], x[N], qxor[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i];
}
int q;
cin >> q;
for (int i = 0;i < q;i++) cin >> l[i] >> r[i] >> x[i];
ll res = 0;
for (int i = 0;i < (1 << q);i++) {
memset(qxor, 0, sizeof qxor);
for (int j = 0;j < q;j++) {
if (i & (1 << j)) {
qxor[l[j]] ^= x[j];
qxor[r[j] + 1] ^= x[j];
}
}
ll ans = 0;
ll sum1 = 0, sum2 = 0;
for (int i = 1;i <= n;i++) {
qxor[i] ^= qxor[i - 1];
b[i] = a[i] ^ qxor[i];
c[i] = b[i] * i;
ans = (ans + 2 * sum2 * b[i] % MOD * (n + 1) % MOD) % MOD;
sum1 = (sum1 + b[i]) % MOD;
sum2 = (sum2 + c[i]) % MOD;
ans = (ans + (n + 1) * b[i] * c[i]) % MOD;
}
ans = (ans - sum2 * sum2 % MOD + MOD) % MOD;
res = (res + ans) % MOD;
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |