QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269410#7881. Computational Complexityucup-team1447#WA 91ms253312kbC++146.2kb2023-11-29 16:45:422023-11-29 16:45:42

Judging History

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

  • [2023-11-29 16:45:42]
  • 评测
  • 测评结果:WA
  • 用时:91ms
  • 内存:253312kb
  • [2023-11-29 16:45:42]
  • 提交

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];

typedef unsigned long long u64;
typedef __uint128_t u128;
struct DIV {
	u64 x;
	inline void init(int v) { x = -1ull / v + 1; }
};
inline u64 operator / (const u64 & x, const DIV & y) {
	return (u128) x * y.x >> 64;
}
DIV DF[20005][4],DG[20005][4],Dval[20005];
DIV Dval2[200005];
int val2[200005];
map<int,int>mp2;
modint f2[200005][2],g2[200005][2],f3[20005][2],g3[20005][2];
int cnt2;
int id2(int x){
	if(mp2.count(x))return mp2[x];
	mp2[x]=++cnt2,val2[cnt2]=x,Dval2[cnt2].init(x);
	return cnt2;
}

__int128 F[20],G[20];

int V=1e15,mx;
int chf[20005][4],chg[20005][4];
int lim;

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];
u128 res[2];

void prework(){
	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){
	//	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];
				}
			}
		}
		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];
				}
			}
		}
	}
}



void work()
{
//	int n=read();
	int n=read();
	if(n<N){
		cout<<f[n].x<<" "<<g[n].x<<"\n";
		return;
	}
	res[0]=res[1]=0;
	
	if(n<=lim){
		modint res[2]={0,0};
		For(i,1,cnt){
			if(val[i]>n)continue;
			int t;
			if(fs[i][0].x||fs[i][1].x){
				For(j,0,3){
					if(chf[i][j]>0){
						if(val[chf[i][j]]>n) For(o,0,1)res[o]+=fs[i][o]*g[0];
					}else{
						t=n/DF[i][j];
						For(o,0,1) res[o]+=fs[i][o]*g[t];
					}
				}
			}
			if(gs[i][0].x||gs[i][1].x){
				For(j,0,3){
					if(chg[i][j]>0){
						if(val[chg[i][j]]>n) For(o,0,1)res[o]+=gs[i][o]*f[0];
					}
					else{
						t=n/DG[i][j];
						For(o,0,1) res[o]+=gs[i][o]*f[t];
					}
				}
			}
		}
		cout<<res[0].x<<" "<<res[1].x<<"\n";
		return;
	}
	
	For(i,1,cnt2){
		int t=n/Dval2[i];
		For(o,0,1) res[o]+=(u128)f2[i][o].x*g[t].x,res[o]+=(u128)g2[i][o].x*f[t].x;
	}
	res[0]%=mod,res[1]%=mod;
	cout<<(ll)res[0]<<" "<<(ll)res[1]<<"\n";
}

bool med;

signed main()
{
//	cerr<<(1.0*(&mbe-&med)/1024576.0)<<"\n";
	f[0]=read(),g[0]=read();
	int T=read();
	mod=read();
	iP=1.0l/mod;
	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);
	For(i,1,cnt) Dval[i].init(val[i]);
	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{
				int v=id2(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{
				int v=id2(u);
			}
		}
	}
	cerr<<"cnt2 "<<cnt2<<"\n";
	prework();
	For(i,1,cnt){
		For(j,0,3){
			int u=val[i]*pri[j];
			if(u<=mx);
			else{
				int v=id2(u);
				For(o,0,1) f2[v][o]+=fs[i][o];
			}
		//	cout<<chf[i][j]<<" \n"[j==3];
		}
		For(j,0,3){
			int u=val[i]*gg[j];
			if(u<=mx);
			else{
				int v=id2(u);
				For(o,0,1) g2[v][o]+=gs[i][o];
			}
		}
	}
	For(i,1,cnt2) lim=max(lim,val2[i]);
	cerr<<"lim "<<lim<<"\n";
	For(_,1,T){
		work();
		if(_%10000==0)cerr<<_<<"\n";
	}
	return 0;
}
/*
114514 1919810 1 123456789123456
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 83ms
memory: 251924kb

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: 84ms
memory: 253312kb

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: 76ms
memory: 253092kb

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: 0
Accepted
time: 75ms
memory: 252224kb

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:

192287632545 510282654057
513694515018 658644741565
90751152870 6088748556
138070013247 301112114677
224113421002 105290451187
630454127249 196841848259
546918129568 526274849982
226761501362 157889210040
135623074930 620463814922
78467045157 602244472172
51639549042 411354142414
329188915935 306494...

result:

ok 4298 numbers

Test #5:

score: -100
Wrong Answer
time: 91ms
memory: 252376kb

input:

46012 72474 6895 931299293479
635558333906
151352929427
186830308154
201652909474
130684521091
862625793178
335372663856
565394770762
609752364488
636658378167
568072145317
23602174799
74849827839
567735061723
964475612065
721588322843
526921882143
141483206690
794896616456
923141155683
443983986019...

output:

737640936783 269480550026
785950579990 586907405473
274405996613 356240054012
164145774405 803378519477
613956922400 426121843045
509646717167 788278629379
95131481441 672600899832
720839818877 52329269906
131977527669 257593035330
737640936783 269480550026
202443098753 171133839273
188615102144 605...

result:

wrong answer 989th numbers differ - expected: '73717573666', found: '155272249660'