Submission #502636

#TimeUsernameProblemLanguageResultExecution timeMemory
502636stanislavpolynIntergalactic ship (IZhO19_xorsum)C++17
17 / 100
2080 ms2252 KiB
#include <bits/stdc++.h> #define fr(i, a, b) for(int i = (a); i <= (b); ++i) #define rf(i, a, b) for(int i = (a); i >= (b); --i) #define fe(x, y) for(auto& x : y) #define fi first #define se second #define pb push_back #define mp make_pair #define mt make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define pw(x) (1LL << (x)) using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define fbo find_by_order #define ook order_of_key template<typename T> bool umn(T& a, T b) { return (a > b ? (a = b, 1) : 0); } template<typename T> bool umx(T& a, T b) { return (a < b ? (a = b, 1) : 0); } using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T> using ve = vector<T>; const int N = 1e3 + 5; const int MOD = 1e9 + 7; int add(int a, int b) { a += b; if(a >= MOD) { return a - MOD; } return a; } int sub(int a, int b) { a -= b; if(a < 0) { return a + MOD; } return a; } int mult(int a, int b) { return 1LL * a * b % MOD; } int n, q; int a[N], was[N]; int pref[N]; ve<array<int, 3>> Q; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); #else // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); #endif cin >> n; fr(i, 1, n) { cin >> a[i]; was[i] = a[i]; } cin >> q; Q.resize(q); int res = 0; fr(i, 0, q - 1) { cin >> Q[i][0] >> Q[i][1] >> Q[i][2]; } fr(mask, 0, pw(q) - 1) { fr(i, 1, n) a[i] = was[i]; fr(i, 0, q - 1) { if(mask & pw(i)) { fr(j, Q[i][0], Q[i][1]) a[j] ^= Q[i][2]; } } int sum1 = 0; int sum2 = 0; fr(i, 1, n) { pref[i] = add(a[i], pref[i - 1]); res = add(res, mult(i, mult(pref[i], pref[i]))); res = sub(res, mult(sum1, mult(2, pref[i]))); res = add(res, sum2); sum1 = add(sum1, pref[i]); sum2 = add(sum2, mult(pref[i], pref[i])); } } cout << res << "\n"; 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...