QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328382 | #7881. Computational Complexity | kkio | WA | 52ms | 12704kb | C++14 | 2.3kb | 2024-02-15 19:49:11 | 2024-02-15 19:49:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define lson(i) (tr[i].ls)
#define rson(i) (tr[i].rs)
#define FIO(file) freopen(file".in","r",stdin), freopen(file".out","w",stdout)
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef __int128_t i128;
typedef __uint128_t u128;
ll LIM,m,q,mod;
ll f[15],g[15];
vector<ll> val;
ll fd[1000000],gd[1000000];
inline ll getf(int x){int pos=lower_bound(val.begin(),val.end(),x)-val.begin();if(pos<0||pos>=val.size()||val[pos]!=x)return 0;else return fd[pos];}
inline ll getg(int x){int pos=lower_bound(val.begin(),val.end(),x)-val.begin();if(pos<0||pos>=val.size()||val[pos]!=x)return 0;else return gd[pos];}
int main()
{
cin>>f[0]>>g[0]>>q>>mod;
LIM=1e15;
for(int i=1;i<=13;i++)
{
f[i]=max((ll)i,g[i/2]+g[i/3]+g[i/5]+g[i/7]);
g[i]=max((ll)i,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
}
for(int i=0;i<=13;i++)f[i]%=mod,g[i]%=mod;
val.push_back(0);
for(ll t=1;t<=min(13ll,LIM);t++)
for(ll z=t;z<=LIM;z*=2)
for(ll t=z;t<=LIM;t*=3)
for(ll z=t;z<=LIM;z*=5)
for(ll t=z;t<=LIM;t*=7)
val.push_back(t);
sort(val.begin(),val.end());
val.resize(unique(val.begin(),val.end())-val.begin());
for(int i=0;i<val.size();i++)
{
if(val[i]<=13){
if(val[i]==0)fd[i]=f[0],gd[i]=g[0];
else fd[i]=(f[val[i]]-f[val[i]-1]+mod)%mod,gd[i]=(g[val[i]]-g[val[i]-1]+mod)%mod;
}
else
{
fd[i]=(val[i]%2==0?getg(val[i]/2):0)+(val[i]%3==0?getg(val[i]/3):0)+(val[i]%5==0?getg(val[i]/5):0)+(val[i]%7==0?getg(val[i]/7):0);fd[i]%=mod;
gd[i]=(val[i]%2==0?getf(val[i]/2):0)+(val[i]%3==0?getf(val[i]/3):0)+(val[i]%4==0?getf(val[i]/4):0)+(val[i]%5==0?getf(val[i]/5):0);gd[i]%=mod;
}
}
for(int i=1;i<val.size();i++)
fd[i]+=fd[i-1],gd[i]+=gd[i-1],fd[i]%=mod,gd[i]%=mod;
for(int i=1;i<=q;i++)
{
ll x;
cin>>x;
int pos=upper_bound(val.begin(),val.end(),x)-val.begin()-1;
//cout<<"!"<<pos<<'\n';
cout<<fd[pos]<<' '<<gd[pos]<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 49ms
memory: 11812kb
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: 51ms
memory: 9412kb
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: 52ms
memory: 9980kb
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: 51ms
memory: 12704kb
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:
232626274055 462398338298 29587069229 389741314810 238276237200 642133207216 540388510197 484089648812 419433771686 111012706085 607140314866 459978197627 433867221338 425868183096 225864883307 250694292399 689859278533 655297710524 418010163005 414360740239 100070739832 278586016742 370085872089 51...
result:
wrong answer 1st numbers differ - expected: '192287632545', found: '232626274055'