QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327783 | #7881. Computational Complexity | maojun | WA | 49ms | 20872kb | C++20 | 1.2kb | 2024-02-15 14:13:47 | 2024-02-15 14:13:48 |
Judging History
answer
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e6;const ll R=1e15;
ll M,f[N],g[N];
int V=0;ll d[N];
inline int gi(ll x){int p=lower_bound(d+1,d+V+1,x)-d;return d[p]==x?p:0;}
inline void init(){
static ll df[N],dg[N];
for(int i=1;i<=13;i++){
f[i]=max((ll)i,g[i/2]+g[i/3]+g[i/5]+g[i/7])%M;df[i]=(f[i]-f[i-1]+M)%M;
g[i]=max((ll)i,f[i/2]+f[i/3]+f[i/4]+f[i/5])%M;dg[i]=(g[i]-g[i-1]+M)%M;
}
set<ll>s;
for(int i=1;i<=13;i++)
for(ll k2=1,w2;(w2=i*k2)<=R;k2*=2)
for(ll k3=1,w3;(w3=w2*k3)<=R;k3*=3)
for(ll k5=1,w5;(w5=w3*k5)<=R;k5*=5)
for(ll k7=1,w7;(w7=w5*k7)<=R;k7*=7)s.insert(w7);
auto F=[&](ll x,int k){return x%k?0:df[gi(x/k)];};
auto G=[&](ll x,int k){return x%k?0:dg[gi(x/k)];};
for(ll x:s){
d[++V]=x;if(x<=13)continue;
df[V]=(G(x,2)+G(x,3)+G(x,5)+G(x,7))%M;f[V]=(f[V-1]+df[V])%M;
dg[V]=(F(x,2)+F(x,3)+F(x,4)+F(x,5))%M;g[V]=(g[V-1]+dg[V])%M;
}
}
int main(){
int T;scanf("%lld%lld%d%lld",&f[0],&g[0],&T,&M);
f[0]%=M;g[0]%=M;init();
for(ll m;T--;){
scanf("%lld",&m);
int p=upper_bound(d+1,d+V+1,m)-d-1;
printf("%lld %lld\n",f[p],g[p]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 44ms
memory: 18456kb
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: 47ms
memory: 18328kb
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: -100
Wrong Answer
time: 49ms
memory: 20872kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 1 1 2 2 3 3 4 4 5 5 6 7 7 7 8 9 9 10
result:
wrong answer 3rd numbers differ - expected: '0', found: '1'