QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269360 | #7881. Computational Complexity | ucup-team1447# | WA | 436ms | 241456kb | C++14 | 4.7kb | 2023-11-29 15:53:31 | 2023-11-29 15:53:32 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
ll mod;
long double iP;
ll mul(ll x,ll y){
ll d=x*iP*y+0.5,s=x*y-d*mod;
return s+((s>>63)&mod);
}
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=mul(x,o.x),*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
bool mbe;
#define N 15000005
modint f[N],g[N];
__int128 F[20],G[20];
int V=1e15,mx;
int chf[20005][4],chg[20005][4];
int pri[4]={2,3,5,7};
int gg[4]={2,3,4,5};
map<int,int>id; int cnt,val[maxn];
void dfs(int u,int now){
// cout<<"dfs "<<u<<" "<<now<<"\n";
if(u==4){
// cout<<"dfs "<<u<<" "<<now<<"\n";
id[now]=++cnt; val[cnt]=now;
return;
}
while(1){
dfs(u+1,now);
now*=pri[u];
if(now>mx)break;
}
}
modint fs[20005][2],gs[20005][2],res[2];
void work()
{
int n=read();
if(n<N){
cout<<f[n].x<<" "<<g[n].x<<"\n";
return;
}
fs[1][0]=1,gs[1][0]=0;
fs[1][1]=0,gs[1][1]=1;
res[0]=res[1]=0;
For(i,1,cnt){
int t=n/val[i];
if(t<N){
For(o,0,1){
res[o]+=fs[i][o]*f[t];
res[o]+=gs[i][o]*g[t];
fs[i][o]=gs[i][o]=0;
}
continue;
}
// cout<<"work "<<i<<" "<<val[i]<<"\n";
// For(j,0,3)cout<<chf[i][j]<<" ";cout<<"\n";
// For(j,0,3)cout<<chg[i][j]<<" ";cout<<"\n";
if(fs[i][0].x||fs[i][1].x){
For(j,0,3){
if(chf[i][j]>0){
For(o,0,1) gs[chf[i][j]][o]+=fs[i][o];
}
else{
// cout<<"tmp "<<n/(-chf[i][j])<<"\n";
For(o,0,1) res[o]+=fs[i][o]*g[n/(-chf[i][j])];
}
}
}
if(gs[i][0].x||gs[i][1].x){
For(j,0,3){
if(chg[i][j]>0){
For(o,0,1) fs[chg[i][j]][o]+=gs[i][o];
}
else{
// cout<<"tmp2 "<<n/(-chg[i][j])<<"\n";
For(o,0,1) res[o]+=gs[i][o]*f[n/(-chg[i][j])];
}
}
}
For(o,0,1) fs[i][o]=gs[i][o]=0;
}
cout<<res[0].x<<" "<<res[1].x<<"\n";
}
bool med;
signed main()
{
// cerr<<(1.0*(&mbe-&med)/1024576.0)<<"\n";
f[0]=read(),g[0]=read();
int T=read();
mod=read();
F[0]=f[0].x,G[0]=g[0].x;
ull mxp=-1;
For(i,1,7){
F[i]=G[i/2]+G[i/3]+G[i/5]+G[i/7];
G[i]=F[i/2]+F[i/3]+F[i/4]+F[i/5];
F[i]=max(F[i],(__int128)i);
G[i]=max(G[i],(__int128)i);
}
For(i,0,7) f[i]=F[i]%mod,g[i]=G[i]%mod;
For(i,8,N-1){
f[i]=g[i/2]+g[i/3]+g[i/5]+g[i/7];
g[i]=f[i/2]+f[i/3]+f[i/4]+f[i/5];
}
mx=V/N+1;
dfs(0,1);
cerr<<cnt<<"\n";
// cout<<"ID "<<id[4]<<"\n";
For(i,1,cnt){
For(j,0,3){
int u=val[i]*pri[j];
if(u<=mx) chf[i][j]=id[u];
else chf[i][j]=-u;
// cout<<chf[i][j]<<" \n"[j==3];
}
For(j,0,3){
int u=val[i]*gg[j];
if(u<=mx) chg[i][j]=id[u];
else chg[i][j]=-u;
}
}
while(T--)work();
return 0;
}
/*
7 1 2
1110001
*/
詳細信息
Test #1:
score: 100
Accepted
time: 75ms
memory: 241456kb
input:
1958 920 10 100000000000 0 1 2 3 10 100 200 1000 19580920 20232023
output:
1958 920 3680 7832 10592 9554 17504 11276 50294 64826 784112 893714 1894550 1905470 12057866 12979424 71481494756 48626708512 28127864908 7251681354
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 61ms
memory: 240920kb
input:
0 0 10 100000000000 0 1 2 3 4 10 20 30 40 100
output:
0 0 1 1 2 2 3 3 4 4 11 12 25 26 41 41 55 58 162 172
result:
ok 20 numbers
Test #3:
score: 0
Accepted
time: 61ms
memory: 240420kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 20 numbers
Test #4:
score: -100
Wrong Answer
time: 436ms
memory: 240972kb
input:
36092 30559 2149 729566623185 909730017626 961811467628 978809456383 494310140318 760462959632 726343527430 220697276132 366336227300 456813204361 569783542145 13854148170 51526515764 564416233246 876430686824 862897449267 956440673661 512777546436 728860125927 799238602356 978766770799 47962348351 ...
output:
412795553785314210 423616803935415642 429462824698858008 447526309672521970 445422401204290920 464713517192144376 188968107407652837 197957990380639837 323231798249042512 339089539547621857 307146719681765879 325202330426692454 69112393132444618 73076107952929137 125252954196525347 13097268765000442...
result:
wrong answer 1st numbers differ - expected: '192287632545', found: '412795553785314210'