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;
const int mod = 1e9 + 7;
int add(int a, int b) {
int res = a + b;
if (res >= mod) {
res -= mod;
}
return res;
}
int subtr(int a, int b) {
int res = a - b;
if (res < 0) {
res += mod;
}
return res;
}
int times(int a, int b) {
long long res = a * 1ll * b;
if (res >= mod) {
res %= mod;
}
return res;
}
void solve() {
int n;
cin >> n;
vector<int> a(n), delta(n + 1);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int q;
cin >> q;
vector<int> l(q), r(q), x(q);
for (int i = 0; i < q; ++i) {
cin >> l[i] >> r[i] >> x[i];
--l[i], --r[i];
}
int ans = 0;
for (int mask = 0; mask < (1 << q); ++mask) {
for (int i = 0; i < q; ++i) {
if ((mask & (1 << i)) != 0) {
delta[l[i]] ^= x[i];
delta[r[i] + 1] ^= x[i];
}
}
for (int i = 0, cur = 0, sum = 0, sumaux = 0; i < n; ++i) {
sumaux = subtr(sumaux, sum);
cur ^= delta[i];
int val = a[i] ^ cur;
ans = add(ans, times(times(val, val), times(i + 1, n - i)));
ans = add(ans, times(val, times(2, sumaux)));
sum = add(sum, times(val, i + 1));
sumaux = add(sumaux, times(times(val, i + 1), n - i));
delta[i] = 0;
}
delta[n] = 0;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
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... |