#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false)
#endif
const int mod = 1e9 + 7, N = 200000;
int main () {
owo;
int n, q;
cin >> n;
vector <vector <int>> cnt(n, vector <int> (32, 0));
for (int i = 0, x; i < n; ++i)
cin >> x, cnt[i][x]++;
cin >> q;
for (int i = 0, l, r, x; i < q; ++i) {
cin >> l >> r >> x, --l;
assert(l + 1 == r);
vector <int> ncnt = cnt[l];
for (int i = 0; i < 32; ++i) {
cnt[l][i ^ x] += ncnt[i];
if (cnt[l][i ^ x] >= mod)
cnt[l][i ^ x] -= mod;
}
}
vector <lli> pre(3101, 0), dp;
pre[0] = 1;
lli ans = 0;
for (int i = 0; i < n; ++i) {
dp.assign(3101, 0);
for (int k = 0; k < 32; ++k) for (int j = 0; j + k < 3101; ++j) {
(dp[j + k] += pre[j] * cnt[i][k]) %= mod;
}
for (int j = 0; j < 3101; ++j) {
pre[j] = dp[j];
(ans += dp[j] * j % mod * j % mod * (n + 1)) %= mod;
}
}
pre.assign(160000, 0);
pre[0] = 1;
for (int i = 0; i < n; ++i) {
dp.assign(160000, 0);
for (int k = 0; k < 32; ++k) for (int j = 0; j + k * (n - i) < 160000; ++j) {
(dp[j + k * (n - i)] += pre[j] * cnt[i][k]) %= mod;
}
pre = dp;
}
for (int j = 0; j < 160000; ++j) {
(ans += mod - dp[j] * j % mod * j % mod) %= mod;
}
assert(0 <= ans && ans < mod);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
920 ms |
2880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
716 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |