#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int MAXN = 1e3 + 10;
const int MOD = 1e9 + 7;
const int MAXLOG = 10;
struct upd
{
int left, right;
int val;
upd()
{
left = right = 1;
val = 0;
}
upd(int _left, int _right, int _val)
{
left = _left;
right = _right;
val = _val;
}
};
int n, q;
int a[MAXN];
int cur[MAXN];
vector < upd > updates;
int ans = 0;
void read()
{
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
cin >> q;
for(int i = 0; i < q; i++)
{
int left, right;
int x;
cin >> left >> right >> x;
upd u = upd(left - 1, right - 1, x);
updates.push_back(u);
}
}
int calc()
{
int qni = 0;
int sum = 0;
int sumsum = 0;
for(int i = 0; i < n; i++)
{
sum = (sum + cur[i]) % MOD;
sumsum = (sumsum + sum) % MOD;
qni = (qni + (sum * sum) % MOD) % MOD;
}
return (( qni * (n + 1) ) % MOD - (sumsum * sumsum) % MOD + MOD) % MOD;
}
void solve()
{
for(int mask = 0; mask < (1 << q); mask++)
{
for(int i = 0; i < n; i++)
{
cur[i] = a[i];
}
for(int j = 0; j < q; j++)
{
int left = updates[j].left;
int right = updates[j].right;
int val = updates[j].val;
if(mask & (1 << j))
{
for(int i = left; i <= right; i++)
{
cur[i] ^= val;
}
}
}
ans = (ans + calc()) % 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 |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
2100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2008 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
310 ms |
348 KB |
Output is correct |
2 |
Correct |
321 ms |
348 KB |
Output is correct |
3 |
Correct |
313 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
310 ms |
348 KB |
Output is correct |
2 |
Correct |
321 ms |
348 KB |
Output is correct |
3 |
Correct |
313 ms |
432 KB |
Output is correct |
4 |
Incorrect |
4 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |