#include<bits/stdc++.h>
#define MAXN 1007
using namespace std;
const int maxa=16;
const long long mod=1e9+7;
int n,a[MAXN],q,l,r,x;
long long ways[MAXN][150];
int br[150];
vector<int> qs[MAXN];
long long dp[150][150],power[100007];
long long cnt[MAXN][MAXN],ans;
void calcdp(){
dp[0][0]=1;
for(int pos=1;pos<=maxa;pos++){
for(int xorr=0;xorr<maxa;xorr++){
if(br[pos-1]==0)dp[pos][xorr]=dp[pos-1][xorr];
else dp[pos][xorr]=(dp[pos-1][xorr] + dp[pos-1][xorr^(pos-1)]*power[br[pos-1]-1] )%mod;
}
}
}
long long calc(int x,int y){
long long res=0;
if(x==y){
for(long long t=0;t<maxa;t++){
res+=((ways[x][t]*(t*t))%mod) * cnt[x][x];
res%=mod;
}
}else{
for(long long t=0;t<maxa;t++){
for(long long s=0;s<maxa;s++){
res+=((ways[x][t]*ways[y][s])%mod) * (((t*s) * cnt[x][y])%mod);
res%=mod;
}
}
}
return res;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
for(int f=i;f<=n;f++){
cnt[i][f]=i*(n-f+1);
if(i!=f)cnt[i][f]*=2;
}
}
cin>>q;
for(int i=1;i<=q;i++){
cin>>l>>r>>x;
qs[l].push_back(x);
qs[r+1].push_back(-x);
}
power[0]=1;
for(int i=1;i<=q;i++){
power[i]=(power[i-1]*2)%mod;
}
for(int i=1;i<=n;i++){
for(int f:qs[i]){
if(f>0)br[f]++;
else br[-f]--;
}
calcdp();
for(int f=0;f<maxa;f++){
ways[i][f]=dp[maxa][a[i]^f];
}
}
for(int i=1;i<=n;i++){
for(int f=i;f<=n;f++){
ans+=calc(i,f);
ans%=mod;
}
}
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
3664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
518 ms |
8624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |