Submission #992940

#TimeUsernameProblemLanguageResultExecution timeMemory
992940NValchanovIntergalactic ship (IZhO19_xorsum)C++17
17 / 100
2058 ms5164 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const ll MAXN = 1e3 + 10; const ll MOD = 1e9 + 7; const ll MAXLOG = 10; struct upd { ll left, right; ll val; upd() { left = right = 1; val = 0; } upd(ll _left, ll _right, ll _val) { left = _left; right = _right; val = _val; } }; ll n, q; ll a[MAXN]; ll cur[MAXN]; vector < upd > updates; ll ans = 0; void read() { cin >> n; for(ll i = 0; i < n; i++) { cin >> a[i]; } cin >> q; for(ll i = 0; i < q; i++) { ll left, right; ll x; cin >> left >> right >> x; upd u = upd(left - 1, right - 1, x); updates.push_back(u); } } ll calc() { ll qni = 0; ll sum = 0; ll sumsum = 0; for(ll i = 0; i < n; i++) { sum = (sum + cur[i]) % MOD; sumsum = (sumsum + sum) % MOD; qni = (qni + (sum * sum) % MOD) % MOD; } return (( qni * (n + 1) ) % MOD - (sumsum * sumsum) % MOD + MOD) % MOD; } void solve() { for(ll mask = 0; mask < (1 << q); mask++) { for(ll i = 0; i < n; i++) { cur[i] = a[i]; } for(ll j = 0; j < q; j++) { ll left = updates[j].left; ll right = updates[j].right; ll val = updates[j].val; if(mask & (1 << j)) { for(ll i = left; i <= right; i++) { cur[i] ^= val; } } } ans = (ans + calc()) % MOD; } cout << ans << endl; } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); 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...