QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283965#7877. Balanced ArrayZxx200611WA 1ms5672kbC++144.3kb2023-12-15 19:33:472023-12-15 19:33:48

Judging History

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

  • [2023-12-15 19:33:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5672kb
  • [2023-12-15 19:33:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

// #define int long long

int n,A[4][2000010];

const int b=1000000007;
const int p[4]={1000000007,1000000009,998244353,19491001};
int pwb[4][4000010],ipwb[4][4000010];
int sbpA[4][2000010];
int ib[4];

inline
int getCharNum(char c)
{
    if(isdigit(c)) return c-'0';
    if(islower(c)) return c-'a'+10;
    if(isupper(c)) return c-'A'+36;
    return -1;
}
inline
long long getStringNum(string s)
{
    long long res=0;
    for(int i=0;i<s.size();i++)
    {
        res=res*62+getCharNum(s[i]);
    }
    return res;
}

inline
int quickPow(int a,int k,int e)
{
    int res=1;
    for(int w=a;k!=0;k>>=1,w=1ll*w*w%p[e])
    {
        if(k&1) res=1ll*res*w%p[e];
    }
    return res;
}
inline
void prework(int e)
{
    ib[e]=quickPow(b,p[e]-2,e);
    pwb[e][0]=ipwb[e][0]=1;
    for(int i=1;i<=2*n+5;i++) pwb[e][i]=1ll*pwb[e][i-1]*b%p[e];
    for(int i=1;i<=2*n+5;i++) ipwb[e][i]=1ll*ipwb[e][i-1]*ib[e]%p[e];

    for(int i=1;i<=n;i++)
    {
        sbpA[e][i]=(sbpA[e][i-1]+1ll*pwb[e][i]*A[e][i]%p[e])%p[e];
    }
    // cout<<"SbpA[ "<<e<<" ] : ";
    // for(int i=1;i<=n;i++)
    // {
    //     cout<<sbpA[e][i]<<" ";
    // }
    // cout<<endl;
}
int S(int l,int r,int e)
{
    return (sbpA[e][r]-sbpA[e][l-1]+p[e])%p[e];
}
inline
bool check(int m,int k,int e)
{
    // cout<<"Checking [ 1 , "<<m<<" ] with k = "<<k<<" , e = "<<e<<endl;
    int d=m%k,c=m/k;      //[1,d]:C=c+1  ,[d+1,k]:C=c
    int pC=c+1,sC=c;
    int res=0;

    int ipwbkm1=quickPow((pwb[e][k]-1+p[e])%p[e],p[e]-2,e);

    // cout<<"[ 1 , "<<d<<" ] : c = "<<pC<<endl;
    int pwi=((1+1ll*((pC-2+p[e])%p[e])*pwb[e][k*pC]%p[e]+p[e])%p[e]-1ll*((pwb[e][k*pC]-pwb[e][k])%p[e]+p[e])%p[e]*ipwbkm1%p[e]+p[e])%p[e];
    int pwik=(1ll*(p[e]-pC+1)*pwb[e][k*pC]+1ll*((pwb[e][k*pC]-pwb[e][k])%p[e]+p[e])%p[e]*ipwbkm1%p[e])%p[e];
    res=(res+1ll*pwi*S(1,d,e)%p[e])%p[e];
    res=(res+(1ll*pwik*S(k+1,k+d,e)%p[e])*ipwb[e][k])%p[e];
    // cout<<"Firpwi = "<<(1+1ll*((pC-2+p[e])%p[e])*pwb[e][k*pC]%p[e]+p[e])%p[e]<<endl;
    // cout<<"Pwb[ "<<e<<" ][ "<<k*pC<<" ] = "<<pwb[e][k*pC]<<endl;
    // cout<<"Secpwi = "<<1ll*((pwb[e][k*pC]-pwb[e][k])%p[e]+p[e])%p[e]*ipwbkm1%p[e]<<endl;
    // cout<<"pwi = "<<pwi<<endl;
    // cout<<"pwik = "<<pwik<<endl;
    // cout<<"res = "<<res<<endl;

    // cout<<"[ "<<d+1<<" , "<<k<<" ] : c = "<<sC<<endl;
    int swi=((1+1ll*((sC-2+p[e])%p[e])*pwb[e][k*sC]%p[e]+p[e])%p[e]-1ll*((pwb[e][k*sC]-pwb[e][k])%p[e]+p[e])%p[e]*ipwbkm1%p[e]+p[e])%p[e];
    int swik=(1ll*(p[e]-sC+1)*pwb[e][k*sC]+1ll*((pwb[e][k*sC]-pwb[e][k])%p[e]+p[e])%p[e]*ipwbkm1%p[e])%p[e];
    res=(res+1ll*swi*S(d+1,k,e)%p[e])%p[e];
    res=(res+(1ll*swik*S(k+d+1,2*k,e)%p[e])*ipwb[e][k])%p[e];
    // cout<<"swi = "<<pwi<<endl;
    // cout<<"swik = "<<pwik<<endl;
    // cout<<"res = "<<res<<endl;
    // cout<<"nowres = "<<1ll*(p[e]-res)*ipwbkm1%p[e]<<endl;

    return sbpA[e][m]==1ll*(p[e]-res)*ipwbkm1%p[e];
}

signed main()
{
    // cout<<quickPow(b,p[0]-2,0)<<endl;
    // cout<<quickPow(b,p[1]-2,1)<<endl;

    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);

    // assert(ib[0]==quickPow(b,p[0]-2,0));
    // assert(ib[1]==quickPow(b,p[1]-2,1));

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        long long v=getStringNum(s);
        A[0][i]=v%p[0];
        A[1][i]=v%p[1];
        A[2][i]=v%p[2];
        A[2][i]=v%p[3];

        // int v;
        // cin>>v;
        // A[0][i]=A[1][i]=A[2][i]=A[3][i]=v;
    }

    // cout<<"A : ";
    // for(int i=1;i<=n;i++) cout<<A[0][i]<<",";
    // cout<<endl;

    prework(0);
    prework(1);
    prework(2);
    prework(3);
    for(int i=1,j=1;i<=n;i++)
    {
        while(j<(i-1)/2&&(check(i,j,0)==0||check(i,j,1)==0||check(i,j,2)==0||check(i,j,3)==0)) j++;

        if(j<=(i-1)/2&&check(i,j,0)&&check(i,j,1)&&check(i,j,2)&&check(i,j,3))
        {
            cout<<1;
            // cout<<"[ "<<1<<" , "<<i<<" ] : k = "<<j<<" is valid"<<endl;
        }
        else
        {
            cout<<0;
            // cout<<"[ "<<1<<" , "<<i<<" ] : No sol"<<endl;
        }
    }
}
/*
62
63 30 80 80 74 78 18 8 94 76 5 79 36 98 89 71 13 38 99 69 43 56 23 32 55 5 7 84 71 39 50 97 48 36 94 50 8 21 56 51 88 79 11 72 73 28 54 27 78 80 82 54 16 32 45 35 41 48 122 63 179 162 

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5596kb

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

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

input:

9
1 2 3 2 5 4 3 8 5

output:

001010111

result:

ok single line: '001010111'

Test #3:

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

input:

9
1C 3f 4S 3h 88 6x 4W d1 8c

output:

001010111

result:

ok single line: '001010111'

Test #4:

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

input:

49
71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke

output:

0000111111001000000000001000000000110000100000001

result:

ok single line: '0000111111001000000000001000000000110000100000001'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 5548kb

input:

48
4LZe2 4LZt4 4LZI6 4LZX8 4LZtY 4LZe2 4LZtX 4LZe2 4LYYd 4LYZ2 4LYZy 4LZe2 4LZtG 4LZtT 4LZe2 4LYtm 6g6ce 4LZe2 4LYYI 8MRDV 4LZu3 6tLzK 4WUft 7EU0p 5FVal 4LZe2 4LZe2 4LZu8 4LZe2 4LXtE 7KcGm 4LYXX 4LYYn 5v3aX 4LZtC 4LZu3 4LZe2 4LYYI 4LZtQ 4TSBp 4LYYB 4LZe2 4MatY 4LYYi 57PgU axOxK 6zQCA 4LZe2

output:

001100000000001100000000000011100000000000001100

result:

wrong answer 1st lines differ - expected: '001100000000001100000000000011100000000000001110', found: '001100000000001100000000000011100000000000001100'