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;
#define int long long
using ll = long long;
const int md = (int)1e9 + 7;
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int q;
cin >> q;
vector<int> l(q + 1), r(q + 1), x(q + 1);
for (int i = 1; i <= q; i++)
cin >> l[i] >> r[i] >> x[i];
int ans = 0;
for (int mk = 0; mk < 1 << q; mk++) {
vector<int> v = a;
for (int i = 1; i <= q; i++) {
if ((mk >> (i - 1)) & 1) {
for (int j = l[i]; j <= r[i]; j++)
v[j] ^= x[i];
}
}
vector<int> p(n + 1);
for (int i = 1; i <= n; i++)
p[i] = p[i - 1] + v[i];
int sm = 0, sms = 0;
for (int i = 1; i <= n; i++) {
int x = (ll)p[i] * p[i] % md;
ans = (ans + (((ll)i * x % md - (ll)p[i] * sm % md + md) % md + sms + md) % md) % md;
sms = (sms + x) % md;
sm = (sm + (p[i] << 1)) % md;
}
}
cout << ans;
}
# | 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... |