#include <iostream>
#include <cstring>
#define int long long
using namespace std;
const int mod=1000000007;
int n,q,a[1001],dp[1010][1010][3],l[100001],r[100001],x[100001],pw=1,res;
void update(int i, int j, int i2, int j2, int idx){
if (j>j2||i>i2)
return;
dp[i][j][idx]++;
dp[i2+1][j][idx]--;
dp[i][j2+1][idx]--;
dp[i2+1][j2+1][idx]++;
}
int ch(int x, int y){
return (!x?!y:(mod+1)/2);
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n;
for (int i=1;i<=n;i++)
cin >> a[i];
cin >> q;
for (int i=1;i<=q;i++){
cin >> l[i] >> r[i] >> x[i];
pw=pw*2%mod;
}
for (int i=0;i<7;i++){
for (int j=0;j<7;j++){
memset(dp,0,sizeof(dp));
for (int k=1;k<=q;k++)
if ((x[k]>>i&1)&(x[k]>>j&1)){
update(l[k],l[k],r[k],r[k],0);
update(l[k],r[k]+1,r[k],n,1);
update(1,l[k],l[k]-1,r[k],2);
}
else if (x[k]>>i&1)
update(l[k],1,r[k],n,1);
else if (x[k]>>j&1)
update(1,l[k],n,r[k],2);
for (int x=1;x<=n;x++)
for (int y=1;y<=n;y++)
for (int k=0;k<3;k++)
dp[x][y][k]+=dp[x][y-1][k]+dp[x-1][y][k]-dp[x-1][y-1][k];
for (int x=1;x<=n;x++)
for (int y=x;y<=n;y++){
int val=(1<<(i+j))*min(x,y)*(n-max(x,y)+1)%mod;
if (x<y)
val=val*2%mod;
int b=(a[x]>>i&1),c=(a[y]>>j&1);
for (int t=0;t<2;t++)
for (int t2=0;t2<2;t2++)
for (int t3=0;t3<2;t3++)
if ((b^t^t2)&(c^t^t3))
res=(res+val*pw%mod*ch(dp[x][y][0],t)%mod*ch(dp[x][y][1],t2)%mod*ch(dp[x][y][2],t3)%mod)%mod;
}
}
}
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
24276 KB |
Output is correct |
2 |
Correct |
121 ms |
24276 KB |
Output is correct |
3 |
Correct |
131 ms |
24276 KB |
Output is correct |
4 |
Correct |
125 ms |
24276 KB |
Output is correct |
5 |
Correct |
128 ms |
24268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
24276 KB |
Output is correct |
2 |
Correct |
121 ms |
24276 KB |
Output is correct |
3 |
Correct |
131 ms |
24276 KB |
Output is correct |
4 |
Correct |
125 ms |
24276 KB |
Output is correct |
5 |
Correct |
128 ms |
24268 KB |
Output is correct |
6 |
Correct |
133 ms |
24280 KB |
Output is correct |
7 |
Correct |
137 ms |
24272 KB |
Output is correct |
8 |
Correct |
132 ms |
24268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
195 ms |
26612 KB |
Output is correct |
2 |
Correct |
142 ms |
24520 KB |
Output is correct |
3 |
Correct |
137 ms |
24184 KB |
Output is correct |
4 |
Correct |
135 ms |
24276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1155 ms |
24284 KB |
Output is correct |
2 |
Correct |
1157 ms |
24276 KB |
Output is correct |
3 |
Correct |
1123 ms |
24276 KB |
Output is correct |
4 |
Correct |
1137 ms |
24292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
24276 KB |
Output is correct |
2 |
Correct |
126 ms |
24224 KB |
Output is correct |
3 |
Correct |
130 ms |
24276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
24276 KB |
Output is correct |
2 |
Correct |
126 ms |
24224 KB |
Output is correct |
3 |
Correct |
130 ms |
24276 KB |
Output is correct |
4 |
Correct |
134 ms |
24404 KB |
Output is correct |
5 |
Correct |
133 ms |
24404 KB |
Output is correct |
6 |
Correct |
131 ms |
24404 KB |
Output is correct |
7 |
Correct |
130 ms |
24404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
24276 KB |
Output is correct |
2 |
Correct |
121 ms |
24276 KB |
Output is correct |
3 |
Correct |
131 ms |
24276 KB |
Output is correct |
4 |
Correct |
125 ms |
24276 KB |
Output is correct |
5 |
Correct |
128 ms |
24268 KB |
Output is correct |
6 |
Correct |
133 ms |
24280 KB |
Output is correct |
7 |
Correct |
137 ms |
24272 KB |
Output is correct |
8 |
Correct |
132 ms |
24268 KB |
Output is correct |
9 |
Correct |
133 ms |
24276 KB |
Output is correct |
10 |
Correct |
126 ms |
24224 KB |
Output is correct |
11 |
Correct |
130 ms |
24276 KB |
Output is correct |
12 |
Correct |
138 ms |
24280 KB |
Output is correct |
13 |
Correct |
139 ms |
24284 KB |
Output is correct |
14 |
Correct |
139 ms |
24280 KB |
Output is correct |
15 |
Correct |
136 ms |
24248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
24276 KB |
Output is correct |
2 |
Correct |
121 ms |
24276 KB |
Output is correct |
3 |
Correct |
131 ms |
24276 KB |
Output is correct |
4 |
Correct |
125 ms |
24276 KB |
Output is correct |
5 |
Correct |
128 ms |
24268 KB |
Output is correct |
6 |
Correct |
133 ms |
24280 KB |
Output is correct |
7 |
Correct |
137 ms |
24272 KB |
Output is correct |
8 |
Correct |
132 ms |
24268 KB |
Output is correct |
9 |
Correct |
133 ms |
24276 KB |
Output is correct |
10 |
Correct |
126 ms |
24224 KB |
Output is correct |
11 |
Correct |
130 ms |
24276 KB |
Output is correct |
12 |
Correct |
134 ms |
24404 KB |
Output is correct |
13 |
Correct |
133 ms |
24404 KB |
Output is correct |
14 |
Correct |
131 ms |
24404 KB |
Output is correct |
15 |
Correct |
130 ms |
24404 KB |
Output is correct |
16 |
Correct |
138 ms |
24280 KB |
Output is correct |
17 |
Correct |
139 ms |
24284 KB |
Output is correct |
18 |
Correct |
139 ms |
24280 KB |
Output is correct |
19 |
Correct |
136 ms |
24248 KB |
Output is correct |
20 |
Correct |
515 ms |
26624 KB |
Output is correct |
21 |
Correct |
462 ms |
26612 KB |
Output is correct |
22 |
Correct |
416 ms |
26612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
24276 KB |
Output is correct |
2 |
Correct |
121 ms |
24276 KB |
Output is correct |
3 |
Correct |
131 ms |
24276 KB |
Output is correct |
4 |
Correct |
125 ms |
24276 KB |
Output is correct |
5 |
Correct |
128 ms |
24268 KB |
Output is correct |
6 |
Correct |
133 ms |
24280 KB |
Output is correct |
7 |
Correct |
137 ms |
24272 KB |
Output is correct |
8 |
Correct |
132 ms |
24268 KB |
Output is correct |
9 |
Correct |
195 ms |
26612 KB |
Output is correct |
10 |
Correct |
142 ms |
24520 KB |
Output is correct |
11 |
Correct |
137 ms |
24184 KB |
Output is correct |
12 |
Correct |
135 ms |
24276 KB |
Output is correct |
13 |
Correct |
1155 ms |
24284 KB |
Output is correct |
14 |
Correct |
1157 ms |
24276 KB |
Output is correct |
15 |
Correct |
1123 ms |
24276 KB |
Output is correct |
16 |
Correct |
1137 ms |
24292 KB |
Output is correct |
17 |
Correct |
133 ms |
24276 KB |
Output is correct |
18 |
Correct |
126 ms |
24224 KB |
Output is correct |
19 |
Correct |
130 ms |
24276 KB |
Output is correct |
20 |
Correct |
134 ms |
24404 KB |
Output is correct |
21 |
Correct |
133 ms |
24404 KB |
Output is correct |
22 |
Correct |
131 ms |
24404 KB |
Output is correct |
23 |
Correct |
130 ms |
24404 KB |
Output is correct |
24 |
Correct |
138 ms |
24280 KB |
Output is correct |
25 |
Correct |
139 ms |
24284 KB |
Output is correct |
26 |
Correct |
139 ms |
24280 KB |
Output is correct |
27 |
Correct |
136 ms |
24248 KB |
Output is correct |
28 |
Correct |
515 ms |
26624 KB |
Output is correct |
29 |
Correct |
462 ms |
26612 KB |
Output is correct |
30 |
Correct |
416 ms |
26612 KB |
Output is correct |
31 |
Correct |
1315 ms |
26620 KB |
Output is correct |
32 |
Correct |
1238 ms |
26632 KB |
Output is correct |
33 |
Correct |
1179 ms |
26612 KB |
Output is correct |
34 |
Correct |
1193 ms |
26700 KB |
Output is correct |
35 |
Correct |
1183 ms |
26716 KB |
Output is correct |
36 |
Correct |
1199 ms |
26612 KB |
Output is correct |