#include "bits/stdc++.h"
#define MAXN 100029
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[MAXN],tmp[7],l[MAXN],r[MAXN],val[MAXN];
vector<int>adj[MAXN];
int cnt[MAXN][7],cntt[MAXN][7][7],cur[7][7],ans[MAXN];
void upd(int x,int val){
for(int i=0;i<7;i++)
if(x>>i&1)
tmp[i]+=val;
}
void upd1(int x,int val,int ind){
for(int i=0;i<7;i++)
if(x>>i&1)
for(int j=0;j<7;j++)
if(x>>j&1)
cntt[ind][i][j]+=val;
}
vector<int>add[MAXN],rem[MAXN];
int mod(ll x){
return (x%INF);
}
int main(){
// freopen("file.in", "r", stdin);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",arr+i);
int q;
scanf("%d",&q);
for(int i=0;i<q;i++){
scanf("%d%d%d",l+i,r+i,val+i);
add[l[i]].pb(i);
rem[r[i]].pb(i);
}
for(int i=1;i<=n;i++){
tr(it,add[i])
upd(val[*it],+1);
for(int j=0;j<7;j++)
cnt[i][j]=tmp[j];
tr(it,rem[i])
upd(val[*it],-1);
}
ll cost;int ii,jj,ca,cb,ins;
for(int i=1;i<=n;i++){
tr(it,add[i])
upd1(val[*it],+1,i);
memset(cur,0,sizeof cur);
for(int j=1;j<=i;j++){
cost=j*(n-i+1);
if(i!=j)cost*=2;
for(int a=0;a<7;a++){//a'th bit in j
for(int b=0;b<7;b++){//b'th bit in i
cur[a][b]+=cntt[j][a][b];
cb=(arr[i]>>b&1);ca=(arr[j]>>a&1);
ins=a+b+q-2;
jj=cnt[j][a]-cur[a][b];
ii=cnt[i][b]-cur[a][b];
assert(ii>=0 and jj>=0);
if(ii and jj)
ans[ins]+=cost;
else if(ii){
if(cur[a][b])
ans[ins]+=cost;
else if(ca)
ans[ins+1]+=cost;
}
else if(jj){
if(cur[a][b])
ans[ins]+=cost;
else if(cb)
ans[ins+1]+=cost;
}
else{
if(ca==cb){
if(cur[a][b])
ans[ins+1]+=cost;
else if(ca and cb)
ans[ins+2]+=cost;
}
}
for(int mod=0;mod<3;mod++)
if(ans[ins+mod]>=INF)
ans[ins+mod]-=INF;
}
}
}
tr(it,rem[i])
upd1(val[*it],-1,l[*it]);
}
int pw=1,res=0;
for(int i=0;i<q+14;i++)
res=mod(res+pw*1LL*ans[i]),pw=mod(pw+pw);
printf("%d\n",res);
return 0;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
42 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
xorsum.cpp:44:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
44 | scanf("%d",arr+i);
| ~~~~~^~~~~~~~~~~~
xorsum.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
xorsum.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
48 | scanf("%d%d%d",l+i,r+i,val+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
7 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
9836 KB |
Output is correct |
2 |
Correct |
11 ms |
7660 KB |
Output is correct |
3 |
Correct |
8 ms |
7404 KB |
Output is correct |
4 |
Correct |
8 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
7788 KB |
Output is correct |
2 |
Correct |
197 ms |
7660 KB |
Output is correct |
3 |
Correct |
202 ms |
7660 KB |
Output is correct |
4 |
Correct |
198 ms |
7532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
8 ms |
7532 KB |
Output is correct |
5 |
Correct |
8 ms |
7532 KB |
Output is correct |
6 |
Correct |
9 ms |
7660 KB |
Output is correct |
7 |
Correct |
8 ms |
7660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
7 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
7 ms |
7404 KB |
Output is correct |
13 |
Correct |
6 ms |
7404 KB |
Output is correct |
14 |
Correct |
7 ms |
7404 KB |
Output is correct |
15 |
Correct |
7 ms |
7404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
7 ms |
7404 KB |
Output is correct |
9 |
Correct |
5 ms |
7404 KB |
Output is correct |
10 |
Correct |
5 ms |
7404 KB |
Output is correct |
11 |
Correct |
5 ms |
7404 KB |
Output is correct |
12 |
Correct |
8 ms |
7532 KB |
Output is correct |
13 |
Correct |
8 ms |
7532 KB |
Output is correct |
14 |
Correct |
9 ms |
7660 KB |
Output is correct |
15 |
Correct |
8 ms |
7660 KB |
Output is correct |
16 |
Correct |
7 ms |
7404 KB |
Output is correct |
17 |
Correct |
6 ms |
7404 KB |
Output is correct |
18 |
Correct |
7 ms |
7404 KB |
Output is correct |
19 |
Correct |
7 ms |
7404 KB |
Output is correct |
20 |
Correct |
110 ms |
11116 KB |
Output is correct |
21 |
Correct |
119 ms |
10860 KB |
Output is correct |
22 |
Correct |
71 ms |
11072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7404 KB |
Output is correct |
2 |
Correct |
5 ms |
7404 KB |
Output is correct |
3 |
Correct |
5 ms |
7404 KB |
Output is correct |
4 |
Correct |
5 ms |
7404 KB |
Output is correct |
5 |
Correct |
5 ms |
7404 KB |
Output is correct |
6 |
Correct |
6 ms |
7404 KB |
Output is correct |
7 |
Correct |
7 ms |
7404 KB |
Output is correct |
8 |
Correct |
7 ms |
7404 KB |
Output is correct |
9 |
Correct |
55 ms |
9836 KB |
Output is correct |
10 |
Correct |
11 ms |
7660 KB |
Output is correct |
11 |
Correct |
8 ms |
7404 KB |
Output is correct |
12 |
Correct |
8 ms |
7404 KB |
Output is correct |
13 |
Correct |
192 ms |
7788 KB |
Output is correct |
14 |
Correct |
197 ms |
7660 KB |
Output is correct |
15 |
Correct |
202 ms |
7660 KB |
Output is correct |
16 |
Correct |
198 ms |
7532 KB |
Output is correct |
17 |
Correct |
5 ms |
7404 KB |
Output is correct |
18 |
Correct |
5 ms |
7404 KB |
Output is correct |
19 |
Correct |
5 ms |
7404 KB |
Output is correct |
20 |
Correct |
8 ms |
7532 KB |
Output is correct |
21 |
Correct |
8 ms |
7532 KB |
Output is correct |
22 |
Correct |
9 ms |
7660 KB |
Output is correct |
23 |
Correct |
8 ms |
7660 KB |
Output is correct |
24 |
Correct |
7 ms |
7404 KB |
Output is correct |
25 |
Correct |
6 ms |
7404 KB |
Output is correct |
26 |
Correct |
7 ms |
7404 KB |
Output is correct |
27 |
Correct |
7 ms |
7404 KB |
Output is correct |
28 |
Correct |
110 ms |
11116 KB |
Output is correct |
29 |
Correct |
119 ms |
10860 KB |
Output is correct |
30 |
Correct |
71 ms |
11072 KB |
Output is correct |
31 |
Correct |
172 ms |
11336 KB |
Output is correct |
32 |
Correct |
183 ms |
11116 KB |
Output is correct |
33 |
Correct |
155 ms |
11244 KB |
Output is correct |
34 |
Correct |
177 ms |
10596 KB |
Output is correct |
35 |
Correct |
176 ms |
10468 KB |
Output is correct |
36 |
Correct |
173 ms |
10604 KB |
Output is correct |