Submission #155502

#TimeUsernameProblemLanguageResultExecution timeMemory
155502qkxwsmIntergalactic ship (IZhO19_xorsum)C++14
0 / 100
690 ms8336 KiB
#include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) #define SZ(x) ((int) ((x).size())) #define ALL(x) (x).begin(), (x).end() #define INF 1000000007 #define MAXN 1013 #define MAXQ 100013 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; ll i2 = (INF + 1) >> 1; int N, Q, M = 128; int arr[MAXN]; ll ev[MAXN][MAXN]; vi guys[MAXN]; array<ll, 128> prob, tmp; array<int, 3> quer[MAXQ]; ll ans; void conv(int x) { FOR(i, 0, M) { tmp[i] = (prob[i] + prob[i ^ x]) * i2; tmp[i] %= INF; } FOR(i, 0, M) { prob[i] = tmp[i]; } return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; FOR(i, 0, N) { cin >> arr[i]; } cin >> Q; FOR(i, 0, Q) { int l, r, x; cin >> l >> r >> x; l--; r--; quer[i] = {l, r, x}; guys[r].PB(i); } FOR(i, 0, N) { FOR(j, 0, M) { prob[j] = 0; } prob[0] = 1; FORD(j, N, i) { //convolve! for (int idx : quer[j]) { int l = quer[idx][0], v = quer[idx][2]; if (l > i) continue; conv(v); } FOR(k, 0, M) { ev[i][j] += (prob[k]) * (arr[i] ^ k) * (arr[j] ^ k); } } } //now we just need expected values of products. FOR(i, 0, N) { FOR(j, 0, i) { ev[i][j] = ev[j][i]; } } FOR(i, 0, N) { FOR(j, 0, N) { ans += ev[i][j] * min((N - i) * (j + 1), (N - j) * (i + 1)); ans %= INF; } } FOR(i, 0, Q) { ans += ans; if (ans >= INF) ans -= INF; } cout << ans << '\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...