QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#134509#6399. Classic: Classical Problemstefanbalaz2WA 124ms15884kbC++146.0kb2023-08-03 21:17:172023-08-03 21:17:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-03 21:17:20]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:15884kb
  • [2023-08-03 21:17:17]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
typedef pair<int,int> pii;

int mod=998244353;
const double dmod=(double)1/mod;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){

    ll ret=(ll)x*y;
    ret=ret-((ll)(dmod*ret))*mod;
    if(ret<0)ret+=mod;
    if(ret<0)ret+=mod;
    if(ret>=mod)ret-=mod;
    if(ret>=mod)ret-=mod;

    return ret;

    return ((ll)x*y)%mod;
}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}

const int maxn=(1<<20);

int proot=step(3,7*17*8);
int prekw[maxn];

int g,a[maxn],n,mp[maxn],b[maxn],c[maxn];
void prek(){
    for(int i=2;i<maxn;i++){
        if(mp[i])continue;
        for(int j=i;j<maxn;j+=i){
            if(!mp[j])mp[j]=i;
        }
    }

    prekw[0]=1;
    for(int i=1;i<maxn;i++)
        prekw[i]=mul(prekw[i-1],proot);

}
vector<int> factorise(int n){

    vector<int>ret;
    while(n>1){
        if(ret.size()==0)ret.pb(mp[n]);
        else if(ret.back()!=mp[n])ret.pb(mp[n]);
        n/=mp[n];
    }
    return ret;
}
int get_gen(int p){

    if(p==2)return 1;

    p--;

    vector<int>fact=factorise(p);

    for(int i=1;i<=p;i++){

        int e=1;
        for(int j=0;j<fact.size();j++){
            if(step(i,p/fact[j])==1){
                e=0;break;
            }
        }

        if(e)return i;
    }

    return -1;
}

vector<int>resetfb;
int resetb=0;
void fft(vector<int>&a,bool invert){

    int n=a.size();

    int j=0;
    for(int i=1;i<n;i++){

        int bit=n>>1;
        for(;bit&j;bit>>=1)j^=bit;
        j^=bit;

        if(i<j)swap(a[i],a[j]);
    }

    for(int len=2;len<=n;len<<=1){

        for(int i=0;i<n;i+=len){

            int cw=maxn/len;
            if(invert)cw=maxn-cw;
            int curr=0;
            for(int j=0;j<len/2;j++){

                int pom1=a[i+j];
                int pom2=mul(a[i+j+len/2],prekw[curr]);

                a[i+j]=add(pom1,pom2);
                a[i+j+len/2]=sub(pom1,pom2);

                curr+=cw;
                if(curr>=maxn)curr-=maxn;

            }

        }

    }


    if(invert){
        int invn=invv(n);
        for(int i=0;i<n;i++)
            a[i]=mul(a[i],invn);
    }

}

int brute_par=500;
vector<int>pol_mul_brute(vector<int>a,vector<int>b){

    int ppp=mod;
    mod=998244353;
    //printf("OPA1\n");
    ///cout<<(int)a.size()-1+(int)b.size()-1+1<<endl;
    vector<int>ret((int)a.size()-1+(int)b.size()-1+1);

    //printf("OPA2\n");
    for(int i=0;i<a.size();i++)
    for(int j=0;j<b.size();j++){
        ret[i+j]=add(ret[i+j], mul(a[i],b[j]) );
    }
    //printf("OPA3\n");

    mod=ppp;
    return ret;
}
void ispis(vector<int>a){
    for(int i=0;i<a.size();i++)printf("%d ",a[i]);
    printf(" ISPIS \n");
}

vector<int> pol_mul(vector<int>a,vector<int>b){

    //printf("OPA1 \n");


    /*if(a.size()*b.size()<brute_par){
        return pol_mul_brute(a,b);
    }*/

    int n=1;
    while(n<(int)a.size()-1+(int)b.size()-1+1)n<<=1;

    a.resize(n);
    b.resize(n);

    int ppp=mod;
    mod=998244353;

    //printf("OPA2 \n");
    fft(a,0);
    /*printf("START\n");
    ispis(b);
    ispis(resetfb);*/
    //fft(b,0);
    if(resetb){
        fft(b,0);
        resetfb=b;
        resetb=0;
    }
    else {
        b=resetfb;
    }

   /* ispis(b);
    ispis(resetfb);
    printf("END\n");*/

    for(int i=0;i<n;i++)
        a[i]=mul(a[i],b[i]);

    fft(a,1);
    mod=ppp;
    //printf("OPA3 \n");
    return a;
}

vector<int> va,vb;
vector<int> check(int x){

    va.clear();
    va.resize(2*mod-2);

    int cn=mod-1;

    for(int i=0;i<va.size();i++){
        if( b[i%cn]<=x )va[i]=1;
        else va[i]=0;
    }

   // printf("%d XXX\n",x);
   // ispis(va);

    vector<int>ret=pol_mul(va,vb);
    vector<int>bla=pol_mul_brute(va,vb);

    /*ispis(ret);
    ispis(bla);
    printf(" AHHA\n");*/

    vector<int>rr;
    for(int i=0;i<cn;i++){
        ///printf()
        if(ret[i+cn-1]==x)rr.pb(b[i]);
    }

    return rr;
}

int main() {

    prek();

    /*vector<int>bb,aa;
    aa.pb(1);
    aa.pb(1);
    bb.pb(2);
    bb.pb(3);
    aa=pol_mul(aa,bb);
    ispis(aa);*/


    ///freopen("test.txt","r",stdin);

    int t;
    scanf("%d",&t);
    while(t--){

        scanf("%d %d",&n,&mod);

        resetb=1;

        int e=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            if(a[i]==0){
                e=1;
                n--;
                i--;
            }
        }

        if(!e){
            printf("%d %d\n0\n",1,1);
            continue;
        }

        g=get_gen(mod);

        /// ako je mex==0 onda dodaj i 0 u rez

        ///printf("%d  GEN\n",g);

        int curr=1;
        for(int i=0;i<mod-1;i++){
            b[i]=curr;
            c[curr]=i;
            //printf("%d %d  BC\n",i,curr);
            curr=mul(curr,g);
        }

        vb.clear();
        vb.resize(mod-1);
        for(int i=1;i<=n;i++){
            vb[c[a[i]]]=1;
        }
        //ispis(vb);
        reverse(vb.begin(),vb.end());

        int l=0;
        int r=mod-1;
        int sr,ret=-1;
        while(l<=r){
            sr=(l+r)/2;

            vector<int>pom=check(sr);

            if(pom.size()==0){
                r=sr-1;
            }
            else{
                l=sr+1;
                ret=sr;
            }
        }
        vector<int>rr=check(ret);
        ret++;
        if(ret==1)rr.pb(0);

        printf("%d %d\n",rr.size(),ret);
        sort(rr.begin(),rr.end());
        for(int i=0;i<rr.size();i++)printf("%d ",rr[i]);
        printf("\n");

    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 18ms
memory: 14924kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 19ms
memory: 15496kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
1 2
1 

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 18ms
memory: 14260kb

input:

7
1 3
0
1 3
1
2 3
1 0
1 3
2
2 3
2 0
2 3
1 2
3 3
0 1 2

output:

3 1
0 1 2 
1 1
0
1 2
1 
1 1
0
1 2
2 
1 1
0
2 3
1 2 

result:

ok 14 lines

Test #4:

score: 0
Accepted
time: 15ms
memory: 15660kb

input:

31
1 5
0
1 5
1
2 5
1 0
1 5
2
2 5
0 2
2 5
2 1
3 5
1 0 2
1 5
3
2 5
0 3
2 5
1 3
3 5
0 1 3
2 5
3 2
3 5
0 2 3
3 5
2 1 3
4 5
2 0 1 3
1 5
4
2 5
4 0
2 5
1 4
3 5
1 4 0
2 5
2 4
3 5
2 4 0
3 5
4 2 1
4 5
1 0 4 2
2 5
4 3
3 5
0 4 3
3 5
3 1 4
4 5
1 4 3 0
3 5
4 3 2
4 5
2 4 0 3
4 5
2 1 4 3
5 5
1 3 0 2 4

output:

5 1
0 1 2 3 4 
1 1
0
1 2
1 
1 1
0
1 2
3 
1 1
0
1 3
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
2 2
2 3 
1 1
0
1 4
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
1 3
3 
1 1
0
1 4
3 
1 1
0
1 3
4 
1 1
0
1 4
2 
1 1
0
1 4
4 
1 1
0
4 5
1 2 3 4 

result:

ok 62 lines

Test #5:

score: 0
Accepted
time: 19ms
memory: 14744kb

input:

127
1 7
0
1 7
1
2 7
1 0
1 7
2
2 7
2 0
2 7
2 1
3 7
2 1 0
1 7
3
2 7
3 0
2 7
3 1
3 7
3 1 0
2 7
2 3
3 7
2 0 3
3 7
2 1 3
4 7
2 0 3 1
1 7
4
2 7
0 4
2 7
1 4
3 7
0 1 4
2 7
4 2
3 7
0 4 2
3 7
1 2 4
4 7
2 4 1 0
2 7
4 3
3 7
3 0 4
3 7
3 1 4
4 7
1 0 4 3
3 7
3 2 4
4 7
3 0 2 4
4 7
4 1 3 2
5 7
4 3 0 1 2
1 7
5
2 7
0 ...

output:

7 1
0 1 2 3 4 5 6 
1 1
0
1 2
1 
1 1
0
1 2
4 
1 1
0
1 3
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
2 2
4 5 
1 1
0
1 4
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
3 3
1 2 4 
1 1
0
2 2
2 5 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
1 5
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
2 2
3 4 
1 1
0
1 3
1 
1 1
0
1 3
3 
1 1
0
1...

result:

ok 254 lines

Test #6:

score: 0
Accepted
time: 25ms
memory: 14588kb

input:

2047
1 11
0
1 11
1
2 11
0 1
1 11
2
2 11
0 2
2 11
2 1
3 11
1 0 2
1 11
3
2 11
3 0
2 11
3 1
3 11
0 3 1
2 11
2 3
3 11
0 2 3
3 11
2 1 3
4 11
1 0 3 2
1 11
4
2 11
0 4
2 11
4 1
3 11
1 4 0
2 11
2 4
3 11
2 0 4
3 11
2 1 4
4 11
0 2 1 4
2 11
3 4
3 11
3 4 0
3 11
3 1 4
4 11
4 1 3 0
3 11
4 3 2
4 11
3 4 0 2
4 11
3 1...

output:

11 1
0 1 2 3 4 5 6 7 8 9 10 
1 1
0
1 2
1 
1 1
0
1 2
6 
1 1
0
1 3
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
2 2
4 6 
1 1
0
1 4
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
1 3
6 
1 1
0
2 3
1 6 
1 1
0
2 2
3 4 
1 1
0
3 2
1 3 4 
1 1
0
1 3
6 
1 1
0
1 5
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
6 9 
1 1
0
1 3
1 
1 1
0
...

result:

ok 4094 lines

Test #7:

score: 0
Accepted
time: 89ms
memory: 15884kb

input:

8191
1 13
0
1 13
1
2 13
0 1
1 13
2
2 13
2 0
2 13
2 1
3 13
2 1 0
1 13
3
2 13
0 3
2 13
1 3
3 13
1 0 3
2 13
2 3
3 13
2 0 3
3 13
3 1 2
4 13
1 3 2 0
1 13
4
2 13
4 0
2 13
4 1
3 13
0 1 4
2 13
2 4
3 13
0 2 4
3 13
2 4 1
4 13
0 1 4 2
2 13
3 4
3 13
3 0 4
3 13
4 1 3
4 13
4 1 0 3
3 13
4 2 3
4 13
3 2 0 4
4 13
3 4...

output:

13 1
0 1 2 3 4 5 6 7 8 9 10 11 12 
1 1
0
1 2
1 
1 1
0
1 2
7 
1 1
0
1 3
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
7 9 
1 1
0
1 4
1 
1 1
0
1 2
10 
1 1
0
2 2
1 10 
1 1
0
1 3
7 
1 1
0
2 3
1 7 
1 1
0
2 2
9 10 
1 1
0
3 2
1 9 10 
1 1
0
1 3
7 
1 1
0
1 5
1 
1 1
0
1 2
8 
1 1
0
2 2
1 8 
1 1
0
2 2
7 8 
1 1
0
1 3...

result:

ok 16382 lines

Test #8:

score: -100
Wrong Answer
time: 124ms
memory: 14688kb

input:

11764
1 17
0
1 17
1
2 17
0 1
1 17
2
2 17
0 2
2 17
2 1
3 17
2 1 0
1 17
3
2 17
3 0
2 17
1 3
3 17
3 0 1
2 17
2 3
3 17
0 3 2
3 17
3 2 1
4 17
3 2 0 1
1 17
4
2 17
0 4
2 17
4 1
3 17
1 4 0
2 17
4 2
3 17
0 2 4
3 17
2 1 4
4 17
2 4 1 0
2 17
3 4
3 17
3 4 0
3 17
4 1 3
4 17
4 1 0 3
3 17
2 4 3
4 17
2 0 3 4
4 17
2 ...

output:

17 1
0 1 1 2 2 4 4 8 8 9 9 13 13 15 15 16 16 
1 1
0
2 2
1 1 
1 1
0
2 2
9 9 
1 1
0
2 3
1 1 
1 1
0
2 2
1 1 
1 1
0
17 1
0 1 1 2 2 4 4 8 8 9 9 13 13 15 15 16 16 
1 1
0
2 3
1 1 
1 1
0
2 4
1 1 
1 1
0
2 2
13 13 
1 1
0
4 2
1 1 13 13 
1 1
0
2 3
9 9 
1 1
0
4 3
1 1 9 9 
1 1
0
4 2
1 1 13 13 
1 1
0
4 3
1 1 2 2 
...

result:

wrong answer 2nd lines differ - expected: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16', found: '0 1 1 2 2 4 4 8 8 9 9 13 13 15 15 16 16 '