QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#292256 | #7647. 树哈希 | CharlieVinnie | 45 | 2902ms | 3844kb | C++17 | 3.4kb | 2023-12-27 22:10:13 | 2023-12-27 22:10:13 |
Judging History
answer
// #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
#undef DEBUG
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=105;
int mod;
inline int qpow(int x,int y){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
inline int ID(int x) { return x&1?mod-1:1; }
class Poly : public vector<int>{
public:
using vector<int>::vector;
friend Poly& operator+= (Poly& A,const Poly& B){
if(A.size()<B.size()) A.resize(B.size());
for(auto i=0u;i<B.size();i++) A[i]=(A[i]+B[i])%mod;
return A;
}
friend Poly& operator-= (Poly& A,const Poly& B){
if(A.size()<B.size()) A.resize(B.size());
for(auto i=0u;i<B.size();i++) A[i]=(A[i]-B[i]+mod)%mod;
return A;
}
friend Poly& operator*= (Poly& A,const Poly& B){
Poly C(A.size()+B.size()-1);
for(auto i=0u;i<A.size();i++) for(auto j=0u;j<B.size();j++) C[i+j]=(C[i+j]+1ll*A[i]*B[j])%mod;
return A=C;
}
friend Poly operator+ (Poly A,const Poly& B) { return A+=B; }
friend Poly operator- (Poly A,const Poly& B) { return A-=B; }
friend Poly operator* (Poly A,const Poly& B) { return A*=B; }
};
Poly pow(Poly A,int k){
Poly res{1}; while(k) { if(k&1) res*=A;; A*=A; k>>=1; }; return res;
}
int n,q,f[N],cp[N],ci[N],inv[N];
int solve(int D){
debuga(f,1,D);
int ans=1ll*qpow(q,f[1])*qpow(f[1],f[1]-1)%mod*cp[n]%mod;
For(i,2,D) if(f[i]) {
Poly A{1};
For(p,1,i-1){
Poly tmp(i+1); For(j,0,i/p) tmp[j*p]=qpow(ci[j],p);
A*=pow(tmp,f[p]); //A.resize(i+1);
}
Poly B=(A-Poly{1})*Poly{q};
Poly G,tmp{1}; For(j,1,i){
tmp*=B;
G+=tmp*Poly{int(1ll*ID(j-1)*inv[j]%mod)};
}
debug(G,1ll*G[i]*cp[n]%mod);
int res=0;
For(k,1,f[i]){
res=(res+1ll*qpow(G[i],k)*(k==f[i]?1:1ll*k*qpow(f[i],f[i]-k-1)%mod)%mod*cp[f[i]]%mod*ci[k]%mod*ci[f[i]-k]%mod*qpow(q,f[i]-k))%mod;
}
ans=1ll*ans*res%mod;
debug(res,i,ans);
}
debug(ans);
For(i,1,D) ans=1ll*ans*ci[f[i]]%mod;
debug(ans);
return ans;
}
int dfs(int dep,int rest){
if(rest==0) return solve(dep-1);
if(rest<dep) return 0;
int res=0; For(i,(dep==1),rest/dep) f[dep]=i,res=(res+dfs(dep+1,rest-i*dep))%mod;
return res;
}
void Init(){
cp[0]=1; For(i,1,100) cp[i]=1ll*cp[i-1]*i%mod;
ci[100]=qpow(cp[100],mod-2); Rev(i,100-1,0) ci[i]=1ll*ci[i+1]*(i+1)%mod;
For(i,1,100) inv[i]=1ll*ci[i]*cp[i-1]%mod;
}
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
// n=30; q=2; mod=998244353;
// cin>>n>>q>>mod;
// Init(); cout<<1ll*dfs(1,n)*inv[n]%mod<<'\n'; //For(i,1,n) cout<<dfs(1,i)<<'\n';
int lim; cin>>lim>>q>>mod; Init();
int B=25;
for(n=1;n<=B;n++) cout<<1ll*dfs(1,n)*inv[n]%mod<<'\n';
For(_,B+1,100) cout<<_<<'\n';
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE
// Started Coding On: December 27 Wed, 16 : 40 : 53
详细
Subtask #1:
score: 45
Acceptable Answer
Test #1:
score: 45
Acceptable Answer
time: 2898ms
memory: 3708kb
input:
100 910342260 935929297
output:
910342260 816177711 569226551 514707635 267406725 391906453 250727611 208481307 81485772 23235693 216730633 285646992 175230876 274553119 174038157 203318484 775234565 322891510 933522659 900692754 745314049 700055439 779013783 855717291 855228480 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4...
result:
points 0.450 You got 45 pts!
Test #2:
score: 45
Acceptable Answer
time: 2897ms
memory: 3744kb
input:
100 222959056 947643239
output:
222959056 358599927 365062242 287299555 872152310 785181552 689517811 751458049 373969559 887125628 238000283 265869067 862846962 717459206 118380127 903859172 38731072 220551290 311944377 678478487 757437607 696077670 937732236 530238679 704937150 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 ...
result:
points 0.450 You got 45 pts!
Test #3:
score: 45
Acceptable Answer
time: 2902ms
memory: 3748kb
input:
100 135352674 235854343
output:
135352674 116843515 129198122 128256418 202034449 101078108 134511179 26177395 38146936 177689345 171471260 220203615 2725266 54489245 202150371 51581049 9159057 174134120 214954721 6858381 164936156 136507834 11983036 56210425 230637079 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46...
result:
points 0.450 You got 45 pts!
Test #4:
score: 45
Acceptable Answer
time: 2897ms
memory: 3844kb
input:
100 538608644 566215339
output:
538608644 365236991 134179965 39370099 416828003 17910602 226317362 529379896 407121368 81806097 249408176 336758120 296361261 35236747 429449088 328368699 409154256 418665686 24463075 203118458 352974481 3351773 506522141 61405204 248921056 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4...
result:
points 0.450 You got 45 pts!
Test #5:
score: 45
Acceptable Answer
time: 2900ms
memory: 3760kb
input:
100 56831820 281897771
output:
56831820 213573518 5338712 114481529 104176011 222091299 258318286 168492731 248042852 279768543 163273831 250332871 125456436 55441194 94771937 85241933 265069860 227132810 189427807 26222782 184487649 201740742 267160664 98981147 101908728 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 4...
result:
points 0.450 You got 45 pts!