#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
60 ms |
348 KB |
Output is correct |
7 |
Correct |
53 ms |
344 KB |
Output is correct |
8 |
Correct |
53 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2083 ms |
5072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2067 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
348 KB |
Output is correct |
3 |
Correct |
11 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
348 KB |
Output is correct |
3 |
Correct |
11 ms |
348 KB |
Output is correct |
4 |
Correct |
1894 ms |
600 KB |
Output is correct |
5 |
Correct |
1854 ms |
604 KB |
Output is correct |
6 |
Correct |
1865 ms |
600 KB |
Output is correct |
7 |
Correct |
1857 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
60 ms |
348 KB |
Output is correct |
7 |
Correct |
53 ms |
344 KB |
Output is correct |
8 |
Correct |
53 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
348 KB |
Output is correct |
10 |
Correct |
12 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
348 KB |
Output is correct |
12 |
Correct |
1238 ms |
472 KB |
Output is correct |
13 |
Correct |
1222 ms |
476 KB |
Output is correct |
14 |
Correct |
1232 ms |
468 KB |
Output is correct |
15 |
Correct |
1229 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
60 ms |
348 KB |
Output is correct |
7 |
Correct |
53 ms |
344 KB |
Output is correct |
8 |
Correct |
53 ms |
348 KB |
Output is correct |
9 |
Correct |
9 ms |
348 KB |
Output is correct |
10 |
Correct |
12 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
348 KB |
Output is correct |
12 |
Correct |
1894 ms |
600 KB |
Output is correct |
13 |
Correct |
1854 ms |
604 KB |
Output is correct |
14 |
Correct |
1865 ms |
600 KB |
Output is correct |
15 |
Correct |
1857 ms |
600 KB |
Output is correct |
16 |
Correct |
1238 ms |
472 KB |
Output is correct |
17 |
Correct |
1222 ms |
476 KB |
Output is correct |
18 |
Correct |
1232 ms |
468 KB |
Output is correct |
19 |
Correct |
1229 ms |
348 KB |
Output is correct |
20 |
Execution timed out |
2068 ms |
5072 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
60 ms |
348 KB |
Output is correct |
7 |
Correct |
53 ms |
344 KB |
Output is correct |
8 |
Correct |
53 ms |
348 KB |
Output is correct |
9 |
Execution timed out |
2083 ms |
5072 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |