QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466730#8520. Xor PartitionsivazivaWA 1ms9784kbC++171.5kb2024-07-08 05:24:132024-07-08 05:24:13

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 05:24:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9784kb
  • [2024-07-08 05:24:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define MAXN 300010
#define MAXM 64
#define MOD 1000000007

long long n;
long long a[MAXN];
long long st2[MAXM];
long long xoor[MAXN][MAXM];
long long pref[MAXN][MAXM][2];
long long dp[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    st2[0]=1;
    for (long long i=1;i<MAXM;i++)
    {
        st2[i]=st2[i-1]*2;
        if (st2[i]>=MOD) st2[i]%=MOD;
    }
    cin>>n;
    for (long long i=1;i<=n;i++) cin>>a[i];
    long long x=0;
    for (long long i=1;i<=n;i++)
    {
        x^=a[i];long long y=x;
        for (long long j=MAXM-1;j>=0;j--)
        {
            if (y<st2[j]) continue;
            xoor[i][j]=1;y-=st2[j];
        }
    }
    for (long long i=0;i<MAXM;i++) pref[0][i][0]=1;
    for (long long i=1;i<=n;i++)
    {
        for (long long j=0;j<MAXM;j++)
        {
            long long val1=st2[j];
            long long val2=pref[i-1][j][1-xoor[i][j]];
            long long val=val1*val2;
            if (val>=MOD) val%=MOD;
            dp[i]+=val;
            if (dp[i]>=MOD) dp[i]%=MOD;
        }
        for (long long j=0;j<MAXM;j++)
        {
            pref[i][j][0]=pref[i-1][j][0];
            pref[i][j][1]=pref[i-1][j][1];
            if (xoor[i][j]==0) pref[i][j][0]+=dp[i];
            else pref[i][j][1]+=dp[i];
            if (pref[i][j][0]>=MOD) pref[i][j][0]%=MOD;
            if (pref[i][j][1]>=MOD) pref[i][j][1]%=MOD;
        }
    }
    cout<<dp[n]<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9760kb

input:

4
7 3 1 2

output:

170

result:

ok 1 number(s): "170"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7656kb

input:

1
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9704kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 9728kb

input:

3
1 2 3

output:

16

result:

ok 1 number(s): "16"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9700kb

input:

4
0 1 0 1

output:

2

result:

ok 1 number(s): "2"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 9784kb

input:

562
918479109239293921 960173570446350728 374394588863436385 418106819278123099 473761712658352147 662782574081105364 824954323015093862 827581845536521847 184394794881199801 820907621998888642 606529830885621237 961790689782125501 582742201855597942 337901250755571075 287706594894797714 18578215893...

output:

582344007

result:

wrong answer 1st numbers differ - expected: '641941658', found: '582344007'