Submission #371189

# Submission time Handle Problem Language Result Execution time Memory
371189 2021-02-26T04:25:46 Z daniel920712 Intergalactic ship (IZhO19_xorsum) C++14
26 / 100
1179 ms 10604 KB
#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;
    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
    {
        for(i=1;i<=N;i++)
        {
            for(j=0;j<32;j++) ttt[0][j]=0;
            ttt[0][all[i]]=0;
            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];
        }
        for(i=1;i<=N;i++)
        {
            for(j=0;j<32;j++) ans+=j*j%MOD*con[i][j]%MOD*Pow[M-xx[i]]%MOD*j%MOD*(M-j+1)%MOD;
            for(j=i+1;j<=N;j++)
            {
                for(k=0;k<32;k++)
                {
                    for(l=0;l<32;l++)
                    {
                        ans+=2*k*l*con[i][k]%MOD*con[j][l]%MOD*Pow[M-xx[i]-xx[j]]%MOD*i%MOD*(M-j+1)%MOD;
                        ans%=MOD;
                    }
                }
            }
        }
    }

    printf("%lld\n",ans);
    return 0;
}

Compilation message

xorsum.cpp: In function 'void F(long long int)':
xorsum.cpp:21:17: warning: unused variable 'j' [-Wunused-variable]
   21 |     long long i,j,t;
      |                 ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
xorsum.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |         scanf("%lld",&all[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
xorsum.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |     scanf("%lld",&M);
      |     ~~~~~^~~~~~~~~~~
xorsum.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   81 |         scanf("%lld %lld %lld",&tt[i].first.first,&tt[i].first.second,&tt[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 8 ms 5100 KB Output is correct
7 Correct 8 ms 5100 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 226 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 5328 KB Output is correct
2 Correct 32 ms 5100 KB Output is correct
3 Correct 24 ms 5120 KB Output is correct
4 Correct 24 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1179 ms 5228 KB Output is correct
2 Correct 1175 ms 5228 KB Output is correct
3 Correct 1176 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1179 ms 5228 KB Output is correct
2 Correct 1175 ms 5228 KB Output is correct
3 Correct 1176 ms 5228 KB Output is correct
4 Incorrect 5 ms 5356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 8 ms 5100 KB Output is correct
7 Correct 8 ms 5100 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 1179 ms 5228 KB Output is correct
10 Correct 1175 ms 5228 KB Output is correct
11 Correct 1176 ms 5228 KB Output is correct
12 Incorrect 4 ms 5100 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 8 ms 5100 KB Output is correct
7 Correct 8 ms 5100 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 1179 ms 5228 KB Output is correct
10 Correct 1175 ms 5228 KB Output is correct
11 Correct 1176 ms 5228 KB Output is correct
12 Incorrect 5 ms 5356 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5120 KB Output is correct
3 Correct 5 ms 5100 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 8 ms 5100 KB Output is correct
7 Correct 8 ms 5100 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Incorrect 226 ms 10604 KB Output isn't correct
10 Halted 0 ms 0 KB -