#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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
3420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
690 ms |
8336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |