#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b){
a += b;
if (a >= MOD){
a -= MOD;
}
return a;
}
int sub(int a, int b){
a -= b;
if (a < 0){
a += MOD;
}
return a;
}
int mul(int a, int b){
return (a * 1ll * b) % MOD;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ON_PC
freopen("input.txt", "r", stdin);
#endif
// freopen("output.txt", "w", stdout);
int T = 1;
// cin >> T;
while (T--){
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
cin >> a[i];
}
int q;
cin >> q;
vector<vector<int>> req(q);
for (int id = 0; id < q; id++){
req[id].resize(3);
for (int i = 0; i < 3; i++){
cin >> req[id][i];
}
}
int res = 0;
for (int i = 1; i <= n; i++){
for (int mask = 0; mask < (1 << q); mask++){
int x = a[i];
for (int j = 0; j < q; j++){
if (mask & (1 << j)){
if (req[j][0] <= i && i <= req[j][1]){
x ^= req[j][2];
}
}
}
res = add(res, mul(mul(x, x), mul(i, n - i + 1)));
}
}
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
for (int mask = 0; mask < (1 << q); mask++){
int x = a[i];
int y = a[j];
for (int k = 0; k < q; k++){
if (mask & (1 << k)){
if (req[k][0] <= i && i <= req[k][1]){
x ^= req[k][2];
}
if (req[k][0] <= j && j <= req[k][1]){
y ^= req[k][2];
}
}
}
int segcnt = mul(i, n - j + 1);
res = add(res, mul(mul(2, segcnt), mul(x, y)));
}
}
}
cout << res << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
193 ms |
212 KB |
Output is correct |
7 |
Correct |
189 ms |
332 KB |
Output is correct |
8 |
Correct |
198 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
353 ms |
6600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2079 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2077 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2077 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
193 ms |
212 KB |
Output is correct |
7 |
Correct |
189 ms |
332 KB |
Output is correct |
8 |
Correct |
198 ms |
300 KB |
Output is correct |
9 |
Execution timed out |
2077 ms |
212 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
193 ms |
212 KB |
Output is correct |
7 |
Correct |
189 ms |
332 KB |
Output is correct |
8 |
Correct |
198 ms |
300 KB |
Output is correct |
9 |
Execution timed out |
2077 ms |
212 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
193 ms |
212 KB |
Output is correct |
7 |
Correct |
189 ms |
332 KB |
Output is correct |
8 |
Correct |
198 ms |
300 KB |
Output is correct |
9 |
Incorrect |
353 ms |
6600 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |