답안 #371164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
371164 2021-02-26T02:51:05 Z daniel920712 Intergalactic ship (IZhO19_xorsum) C++14
26 / 100
1182 ms 3692 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

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];
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,x=1,y=1,z=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;
    }

    for(i=0;i<M;i++)
    {
        z*=2;
        z%=MOD;
    }

    //printf("%lld\n",M);
    for(i=0;i<M;i++) scanf("%lld %lld %lld",&tt[i].first.first,&tt[i].first.second,&tt[i].second);
    if(M<=20)
    {
        F(0);

    }
    else
    {
        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;
                }

            }
        }
    }

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

Compilation message

xorsum.cpp: In function 'void F(long long int)':
xorsum.cpp:14:17: warning: unused variable 'j' [-Wunused-variable]
   14 |     long long i,j,t;
      |                 ^
xorsum.cpp: In function 'int main()':
xorsum.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
xorsum.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |         scanf("%lld",&all[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
xorsum.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |     scanf("%lld",&M);
      |     ~~~~~^~~~~~~~~~~
xorsum.cpp:73:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   73 |     for(i=0;i<M;i++) scanf("%lld %lld %lld",&tt[i].first.first,&tt[i].first.second,&tt[i].second);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 3692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 364 KB Output is correct
2 Correct 29 ms 364 KB Output is correct
3 Correct 20 ms 364 KB Output is correct
4 Correct 21 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1182 ms 416 KB Output is correct
2 Correct 1177 ms 416 KB Output is correct
3 Correct 1176 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1182 ms 416 KB Output is correct
2 Correct 1177 ms 416 KB Output is correct
3 Correct 1176 ms 492 KB Output is correct
4 Incorrect 2 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
9 Correct 1182 ms 416 KB Output is correct
10 Correct 1177 ms 416 KB Output is correct
11 Correct 1176 ms 492 KB Output is correct
12 Incorrect 1 ms 512 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
9 Correct 1182 ms 416 KB Output is correct
10 Correct 1177 ms 416 KB Output is correct
11 Correct 1176 ms 492 KB Output is correct
12 Incorrect 2 ms 492 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
9 Incorrect 29 ms 3692 KB Output isn't correct
10 Halted 0 ms 0 KB -