# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
371196 | daniel920712 | Intergalactic ship (IZhO19_xorsum) | C++14 | 1189 ms | 9708 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
long long all[200005];
long long a[200005];
long long b[200005];
long long c[200005];
pair < pair < long long , long long > , long long > tt[200005];
vector < long long > how[200005];
long long con[105][35]={0};
long long ttt[100005][35]={0};
long long Pow[200005]={0};
long long xx[200005]={0};
long long ans=0,N,M,MOD=1e9+7;
void F(long long here)
{
long long i,j,t;
if(here==M)
{
t=0;
for(i=1;i<=N;i++)
{
t+=2*all[i]*(N-i+1)%MOD;
t%=MOD;
}
for(i=1;i<=N;i++)
{
ans+=all[i]*all[i]*i*(N-i+1);
ans%=MOD;
t-=2*all[i]*(N-i+1)%MOD;
t+=MOD;
t%=MOD;
ans+=all[i]*i*t%MOD;
ans%=MOD;
}
return;
}
F(here+1);
for(i=tt[here].first.first;i<=tt[here].first.second;i++) all[i]^=tt[here].second;
F(here+1);
for(i=tt[here].first.first;i<=tt[here].first.second;i++) all[i]^=tt[here].second;
}
int main()
{
long long i,j,k,l,x=1,y=1,z=1,ok=1,ans2=0;
scanf("%lld",&N);
for(i=1;i<=N;i++)
{
scanf("%lld",&all[i]);
a[i]=all[i];
b[i]=-1;
c[i]=-1;
}
scanf("%lld",&M);
for(i=0;i<M-2;i++)
{
x*=2;
x%=MOD;
}
for(i=0;i<M-1;i++)
{
y*=2;
y%=MOD;
}
Pow[0]=1;
for(i=0;i<M;i++)
{
Pow[i+1]=Pow[i]*2%MOD;
z*=2;
z%=MOD;
}
for(i=0;i<M;i++)
{
scanf("%lld %lld %lld",&tt[i].first.first,&tt[i].first.second,&tt[i].second);
if(tt[i].first.second-tt[i].first.first) ok=0;
how[tt[i].first.first].push_back(tt[i].second);
xx[tt[i].first.first]++;
}
if(M<=20) F(0);
else if(ok==0)
{
for(i=0;i<M;i++)
{
for(j=tt[i].first.first;j<=tt[i].first.second;j++)
{
b[j]=a[j]^tt[i].second;
c[j]=i;
}
}
for(i=1;i<=N;i++)
{
if(b[i]==-1)
{
ans+=z*a[i]*a[i]*i*(N-i+1)%MOD;
ans%=MOD;
}
else
{
ans+=y*a[i]*a[i]*i*(N-i+1)%MOD;
ans%=MOD;
ans+=y*b[i]*b[i]*i*(N-i+1)%MOD;
ans%=MOD;
}
for(j=i+1;j<=N;j++)
{
if(b[i]==-1&&b[j]==-1)
{
ans+=2*z*a[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
}
else if(b[i]==-1)
{
ans+=2*y*a[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*y*a[i]*b[j]*i*(N-j+1)%MOD;
ans%=MOD;
}
else if(b[j]==-1)
{
ans+=2*y*a[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*y*b[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
}
else if(c[i]==c[j])
{
ans+=2*y*a[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*y*b[i]*b[j]*i*(N-j+1)%MOD;
ans%=MOD;
}
else
{
ans+=2*x*a[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*x*b[i]*b[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*x*a[i]*b[j]*i*(N-j+1)%MOD;
ans%=MOD;
ans+=2*x*b[i]*a[j]*i*(N-j+1)%MOD;
ans%=MOD;
}
}
}
}
else
{
//F(0);
for(i=1;i<=N;i++)
{
for(j=0;j<32;j++) ttt[0][j]=0;
ttt[0][all[i]]=1;
for(j=0;j<xx[i];j++)
{
for(k=0;k<32;k++) ttt[j+1][k]=ttt[j][k];
for(k=0;k<32;k++)
{
ttt[j+1][k^how[i][j]]+=ttt[j][k];
ttt[j+1][k^how[i][j]]%=MOD;
}
}
for(j=0;j<32;j++)
{
con[i][j]=ttt[xx[i]][j];
//if(con[i][j]) printf("%lld %lld %lld\n",i,j,con[i][j]);
}
}
ans2=0;
for(i=1;i<=N;i++)
{
for(j=0;j<32;j++)
{
ans2+=j*j%MOD*con[i][j]%MOD*Pow[M-xx[i]]%MOD*i%MOD*(N-i+1)%MOD;
ans2%=MOD;
}
for(j=i+1;j<=N;j++)
{
//printf("aa %lld\n",Pow[M-xx[i]-xx[j]]);
for(k=0;k<32;k++)
{
for(l=0;l<32;l++)
{
ans2+=2*k*l*con[i][k]%MOD*con[j][l]%MOD*Pow[M-xx[i]-xx[j]]%MOD*i%MOD*(N-j+1)%MOD;
ans2%=MOD;
}
}
}
}
//printf("%lld %lld\n",ans,ans2);
ans=ans2;
}
printf("%lld\n",ans);
return 0;
}
//936
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |