QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202418#6399. Classic: Classical Problemucup-team870Compile Error//C++203.8kb2023-10-06 01:36:512023-10-06 01:36:51

Judging History

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

  • [2023-10-06 01:36:51]
  • 评测
  • [2023-10-06 01:36:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
#define db double
const int N=4e5+5, mod =998244353, G = 3;
ll qp(ll x, ll y) {
    ll res = 1;
    while (y) {
        if (y & 1)res = res * x % mod;
        x = x * x % mod; y >>= 1;
    }return res;
}
const int Gi = qp(G, mod - 2);
namespace Poly {
    typedef vi poly;
    int limit = 1, L = 0; int r[N * 4];
    void NTT(poly& A, int type) { //下标在[0,limit)范围内,数组开四倍即可
        A.resize(limit);
        for (int i = 0; i < limit; i++)
            if (i < r[i]) swap(A[i], A[r[i]]);
        for (int mid = 1; mid < limit; mid <<= 1) {
            ll Wn = qp(type == 1 ? G : Gi, (mod - 1) / (mid << 1)); //G是模数的原根,Gi是逆元
            for (int j = 0; j < limit; j += (mid << 1)) {
                ll w = 1; //ll不一定够
                for (int k = 0; k < mid; k++, w = (w * Wn) % mod) {
                    int x = A[j + k], y = w * A[j + k + mid] % mod; //int不一定够
                    A[j + k] = (x + y) % mod, A[j + k + mid] = (x - y + mod) % mod;
                }
            }
        }
    }
    poly operator + (poly a, poly b) {
        int n = max(a.size(), b.size());
        a.resize(n); b.resize(n);
        rep(i, 0, n - 1)a[i] = (a[i] + b[i]) % mod;
        return a;
    }
    poly operator - (poly a, poly b) {
        int n = max(a.size(), b.size());
        a.resize(n); b.resize(n);
        rep(i, 0, n - 1)a[i] = (a[i] - b[i] + mod) % mod;
        return a;
    }
    void poly_mul_init(poly& a, poly& b) {
        limit = 1; L = 0;
        int N = a.size() - 1, M = b.size() - 1;
        while (limit <= N + M) limit <<= 1, L++;
        for (int i = 0; i < limit; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (L - 1));
    }
    poly poly_mul(poly a, poly b) { //原先的a,b不需要维持原状的话,可以加&
        int n = a.size() + b.size() - 1;
        poly_mul_init(a, b);
        NTT(a, 1); NTT(b, 1);
        for (int i = 0; i < limit; i++) a[i] = 1ll * a[i] * b[i] % mod; //a[i]为ll不一定够
        NTT(a, -1);
        ll INV = qp(limit, mod - 2);
        rep(i, 0, limit - 1)a[i] = a[i] * INV % mod;
        a.resize(n); return a;
    }
}


void slv(){
    int n,p;cin>>n>>p;
    vi pw(p+1),lg(p+1); int g=-1;
    auto ok=[&](int g){
        pw[0]=pw[p-1]=1;
        rep(i,1,p-2){
            pw[i]=1ll*pw[i-1]*g%p; if(pw[i]==1)return false;
        }
        rep(i,0,p-2)lg[pw[i]]=i;
        return true;
    };
    rep(i,1,p-1){
        if(ok(i)){g=i;break;}
    }
    assert(g!=-1); //p=2时g=1
    vi a(n+1),b((p-1)*2);
    int fl=0;
    rep(i,1,n){
        cin>>a[i]; if(a[i]==0)fl=1;
    }
    if(!fl){
        cout<<"1 1\n0\n";return;
    }
    if(n==1){
        cout<<p<<" 1\n";
        rep(i,0,p-1)cout<<i<<' '; cout<<'\n';
        return;
    }
    rep(i,1,n){
        if(a[i]==0)continue;
        b[(p-1-lg[a[i]])%(p-1)]=1;
    }
    rep(i,0,p-1)b[i+p-1]=b[i];
    vi ans;
    auto ck=[&](int res){
        vi c(p-1);
        rep(i,1,res)c[lg[i]]=1;
        d=Poly::poly_mul(b,c);
        ans.clear();
        rep(i,0,(int)d.size()-1){
            if(d[i]==res)ans.push_back(pw[i%(p-1)]);
        }
        return ans.size()>0;
    };
    int l=1,r=p-1;
    while(l<=r){
        int mid=l+r>>1;
        if(ck(mid))l=mid+1;
        else r=mid-1;
    }
    ck(l-1);
    sort(ans.begin(),ans.end());
    ans.resize(unique(ans.begin(),ans.end())-ans.begin());
    cout<<ans.size()<<' '<<l<<'\n';
    for(auto v:ans)cout<<v<<' '; cout<<'\n';
}
signed main(){
    IOS
    int T;cin>>T;
    while(T--)slv();
}
/*
1
3 5
0 2 3
*/

Details

answer.code: In lambda function:
answer.code:105:9: error: ‘d’ was not declared in this scope
  105 |         d=Poly::poly_mul(b,c);
      |         ^