QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#330832#7881. Computational ComplexityJryno1TL 941ms29192kbC++141.9kb2024-02-17 19:39:062024-02-17 19:39:06

Judging History

This is the latest submission verdict.

  • [2024-02-17 19:39:06]
  • Judged
  • Verdict: TL
  • Time: 941ms
  • Memory: 29192kb
  • [2024-02-17 19:39:06]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int lim=3e15,lowlim=15;
int f[20],g[20],df[20],dg[20];
int mod,f0,g0,T;
map<int,int>valf,valg,visf,visg;
vector<int>F,G,Fpos,Gpos;
priority_queue<int,vector<int>,greater<int>>havf,havg;
int FtoG[4]={2,3,4,5},GtoF[4]={2,3,5,7};
signed main(){
	cin.tie(0),cout.tie(0),ios::sync_with_stdio(false);
	cin>>(f[0]=df[0])>>(g[0]=dg[0])>>T>>mod;
	F.push_back(f[0]),Fpos.push_back(0),G.push_back(g[0]),Gpos.push_back(0);
	for(int i=1;i<=lowlim;i++){
		f[i]=max(i,g[i/2]+g[i/3]+g[i/5]+g[i/7]);
		g[i]=max(i,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
		df[i]=f[i]-f[i-1],dg[i]=g[i]-g[i-1];
		valf[i]=df[i],valg[i]=dg[i];
		havf.push(i),havg.push(i);
	}
	while(havf.size()||havg.size()){
		if(havf.size()&&(!havg.size()||havf.top()<=havg.top())){
			int now=havf.top();
//			if(now<21)cout<<"CHK:"<<now<<" "<<valf[now]<<"\n";
//			cout<<"F:"<<now<<"\n";
			havf.pop();
			int dnow=valf[now];
			F.push_back(dnow),Fpos.push_back(now);
			for(int i=0;i<4;i++){
				if(now*FtoG[i]>lowlim&&now*FtoG[i]<lim){
					if(!visg[now*FtoG[i]])visg[now*FtoG[i]]=1,havg.push(now*FtoG[i]);
					valg[now*FtoG[i]]=(valg[now*FtoG[i]]+dnow)%mod;
				}
			}
		} else {
			int now=havg.top();
//			cout<<"G:"<<now<<"\n";
			havg.pop();
			int dnow=valg[now];
			G.push_back(dnow),Gpos.push_back(now);
			for(int i=0;i<4;i++){
				if(now*GtoF[i]>lowlim&&now*GtoF[i]<lim){
					if(!visf[now*GtoF[i]])visf[now*GtoF[i]]=1,havf.push(now*GtoF[i]);
					valf[now*GtoF[i]]=(valf[now*GtoF[i]]+dnow)%mod;
				}
			}
		}
	}	
	while(T--){
		int n,res=0;
		cin>>n;
		int pos=lower_bound(Fpos.begin(),Fpos.end(),n+1)-Fpos.begin();
		pos--;
		for(int i=0;i<=pos;i++)res=(res+F[i])%mod;
		cout<<res<<" ";
		res=0;
		pos=lower_bound(Gpos.begin(),Gpos.end(),n+1)-Gpos.begin();
		pos--;
		for(int i=0;i<=pos;i++)res=(res+G[i])%mod;
		cout<<res<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 200ms
memory: 29116kb

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: 184ms
memory: 29164kb

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: 191ms
memory: 29136kb

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: 941ms
memory: 29192kb

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
Time Limit Exceeded

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: