Submission #677763

#TimeUsernameProblemLanguageResultExecution timeMemory
677763AlcabelIntergalactic ship (IZhO19_xorsum)C++17
17 / 100
2067 ms2248 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...