#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 100007
using namespace std;
struct query{
int type,val;
};
const int maxa=128;
const long long mod=1e9+7;
int n,d[MAXN],q,l[MAXN],r[MAXN],x[MAXN];
long long dp[507][150][150];
long long power[100007];
long long cnt[1007][1007],ans;
vector<query> w;
int li[207][3],tim,rest;
int br[207][3],qs[MAXN];
long long ways[MAXN][150];
vector<long long> poss[MAXN];
void calcdp(){
dp[0][0][0]=1;
for(int pos=1;pos<=int(w.size());pos++){
for(int s=0;s<maxa;s++){
int t=s;
if(w[pos-1].type==0){
dp[pos][s][t]=(dp[pos-1][s][t] + dp[pos-1][s^w[pos-1].val][t])*power[br[w[pos-1].val][0]-1];
}
if(w[pos-1].type==1){
dp[pos][s][t]=(dp[pos-1][s][t] + dp[pos-1][s][t^w[pos-1].val])*power[br[w[pos-1].val][1]-1];
}
if(w[pos-1].type==2){
dp[pos][s][t]=(dp[pos-1][s][t] + dp[pos-1][s^w[pos-1].val][t^w[pos-1].val])*power[br[w[pos-1].val][2]-1];
}
dp[pos][s][t]%=mod;
}
}
}
bool in(int a,int l,int r){
return a>=l and a<=r;
}
long long calc(int a,int b){
long long res=0;
/*rest=0; tim++;
w.clear();
for(int i=0;i<=200;i++){
for(int f=0;f<3;f++)br[i][f]=0;
}
for(int i=1;i<=q;i++){
if(!in(a,l[i],r[i]) and !in(b,l[i],r[i]))rest++;
if(in(a,l[i],r[i]) and !in(b,l[i],r[i])){
if(li[x[i]][0]!=tim)w.push_back({0,x[i]});
li[x[i]][0]=tim;
br[x[i]][0]++;
}
if(!in(a,l[i],r[i]) and in(b,l[i],r[i])){
if(li[x[i]][1]!=tim)w.push_back({1,x[i]});
li[x[i]][1]=tim;
br[x[i]][1]++;
}
if(in(a,l[i],r[i]) and in(b,l[i],r[i])){
if(li[x[i]][2]!=tim)w.push_back({2,x[i]});
li[x[i]][2]=tim;
br[x[i]][2]++;
}
}
calcdp();*/
for(long long s:poss[a]){
for(long long t:poss[b]){
if(a==b and s==t) res+=((s*t*cnt[a][b])%mod) * ((ways[a][s]*power[q-qs[a]])%mod);
else if(a!=b)res+=((s*t*cnt[a][b])%mod) * ((((ways[a][s]*ways[b][t])%mod)*power[q-qs[a]-qs[b]])%mod);
res%=mod;
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>d[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[i]>>r[i]>>x[i];
}
power[0]=1;
for(int i=1;i<=q;i++){
power[i]=(power[i-1]*2)%mod;
}
for(int z=1;z<=n;z++){
rest=0; tim++;
w.clear();
for(int i=0;i<=200;i++){
for(int f=0;f<3;f++)br[i][f]=0;
}
for(int i=1;i<=q;i++){
if(!in(z,l[i],r[i]) and !in(z,l[i],r[i]))rest++;
if(in(z,l[i],r[i]) and !in(z,l[i],r[i])){
if(li[x[i]][0]!=tim)w.push_back({0,x[i]});
li[x[i]][0]=tim;
br[x[i]][0]++;
}
if(!in(z,l[i],r[i]) and in(z,l[i],r[i])){
if(li[x[i]][1]!=tim)w.push_back({1,x[i]});
li[x[i]][1]=tim;
br[x[i]][1]++;
}
if(in(z,l[i],r[i]) and in(z,l[i],r[i])){
qs[z]++;
if(li[x[i]][2]!=tim)w.push_back({2,x[i]});
li[x[i]][2]=tim;
br[x[i]][2]++;
}
}
calcdp();
for(int f=0;f<maxa;f++){
ways[z][f]=(dp[int(w.size())][d[z]^f][d[z]^f])%mod;
if(ways[z][f]>0)poss[z].push_back(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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
11088 KB |
Output is correct |
2 |
Correct |
48 ms |
8540 KB |
Output is correct |
3 |
Correct |
15 ms |
4696 KB |
Output is correct |
4 |
Correct |
3 ms |
3676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
11096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4520 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |