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 <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll MAXN = 1e3 + 10;
const ll MOD = 1e9 + 7;
const ll MAXLOG = 7;
struct upd
{
ll left, right;
ll val;
upd()
{
left = right = 1;
val = 0;
}
upd(ll _left, ll _right, ll _val)
{
left = _left;
right = _right;
val = _val;
}
};
ll n, q;
ll a[MAXN];
ll cur[MAXN];
ll pow2[MAXN];
vector < upd > updates;
ll ans = 0;
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
cin >> q;
for(int i = 1; i <= q; i++)
{
ll left, right;
ll x;
cin >> left >> right >> x;
upd u = upd(left, right, x);
updates.push_back(u);
}
}
void solve()
{
pow2[0] = 1;
for(int i = 1; i < MAXN; i++)
{
pow2[i] = (pow2[i - 1] * 2) % MOD;
}
for(int i = 1; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
ll cnt = (i * (n - j + 1)) % MOD;
ll type;
if(i != j)
type = (cnt * 2) % MOD;
else
type = cnt;
ll cursum = 0;
for(int bit1 = 0; bit1 < MAXLOG; bit1++)
{
for(int bit2 = 0; bit2 < MAXLOG; bit2++)
{
vector < vector < ll > > dp;
dp.resize(2);
dp[0].resize(4);
dp[1].resize(4);
dp[0][(bool(a[i] & (1 << bit1)) << 1) | (bool(a[j] & (1 << bit2)))] = 1;
for(int k = 0; k < q; k++)
{
dp[1] = dp[0];
int in1 = 0;
int in2 = 0;
if(updates[k].left <= i && i <= updates[k].right)
in1 = (bool(updates[k].val & (1 << bit1)));
if(updates[k].left <= j && j <= updates[k].right)
in2 = (bool(updates[k].val & (1 << bit2)));
int h = (in1 << 1) | in2; /// 00; 01; 10; 11
for(int x = 0; x < 4; x++)
{
dp[1][x ^ h] = (dp[1][x ^ h] + dp[0][x]) % MOD;
}
swap(dp[1], dp[0]);
}
cursum = (cursum + (pow2[bit1 + bit2] * dp[0][3]) % MOD) % MOD;
}
}
cursum = (cursum * type) % MOD;
ans = (ans + cursum) % MOD;
}
}
cout << ans << endl;
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
return 0;
}
# | 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... |