# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
903922 | LucaLucaM | Intergalactic ship (IZhO19_xorsum) | C++17 | 2053 ms | 1776 KiB |
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 <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#warning That's the baby, that's not my baby
typedef long long ll;
const int mod = 1e9 + 7;
struct Update {
int l, r, x;
};
int power(int a, int b) {
int p = 1;
while (b) {
if (b & 1) {
p = (ll) p * a % mod;
}
a = (ll) a * a % mod;
b >>= 1;
}
return p;
}
int solve(std::vector<int> a) {
int n = (int) a.size();
ll ret = 0;
for (int i = 0; i < n; i++) {
ret += (ll) a[i] * a[i] % mod * (i + 1) * (n - i) % mod;
for (int j = i + 1; j < n; j++) {
ret += (ll) 2 * a[i] * a[j] % mod * (i + 1) * (n - j) % mod;
}
}
return ret % mod;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
std::vector<int> a(n);
for (auto &x : a) {
std::cin >> x;
}
int q;
std::cin >> q;
if (q == 0) {
std::cout << solve(a);
return 0;
}
std::vector<Update> Q(q);
for (auto &[l, r, x] : Q) {
std::cin >> l >> r >> x;
--l, --r;
}
ll answer = 0;
for (int mask = 0; mask < (1 << q); mask++) {
std::vector<int> b = a;
for (int i = 0; i < q; i++) {
if (mask & (1 << i)) {
for (int k = Q[i].l; k <= Q[i].r; k++) {
b[k] ^= Q[i].x;
}
}
answer += solve(b);
}
}
std::cout << answer % mod;
return 0;
}
Compilation message (stderr)
# | 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... |