QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328276#7881. Computational ComplexityxinhaowenWA 103ms16268kbC++142.1kb2024-02-15 18:49:202024-02-15 18:49:21

Judging History

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

  • [2024-02-15 18:49:21]
  • 评测
  • 测评结果:WA
  • 用时:103ms
  • 内存:16268kb
  • [2024-02-15 18:49:20]
  • 提交

answer

#include<map>
#include<queue>
#include<cstdio>
#include<algorithm>
#define int long long
// #define inf 0x3f3f3f3f
// #define getchar getchar_unlocked
// #define putchar putchar_unlocked
template<typename T>void read(T &x){
	x=0;bool f=0;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f)x=-x;
}
void write(char x){putchar(x);}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x=-x;
	char stk[24];int cnt=0;
	do stk[++cnt]=x%10+48,x/=10;while(x);
	for(;cnt;)putchar(stk[cnt--]);
}
template<typename T,typename ...Args>void read(T &x,Args &...args){read(x);read(args...);}
template<typename T,typename ...Args>void write(T x,Args ...args){write(x);write(args...);}
template<typename T>T min(T x,T y){return x<y?x:y;}
template<typename T>T max(T x,T y){return x>y?x:y;}
const int maxn=1e6+4,lim=1e15;int id[maxn],tot,f[maxn],g[maxn],T,mod;
std::priority_queue<int,std::vector<int>,std::greater<int> >que;std::map<int,bool>mp;
int get_f(int x,int y){
	if(x%y)return 0;
	int tmp=std::lower_bound(id+1,id+tot+1,x/y)-id;
	return f[tmp];
}
int get_g(int x,int y){
	if(x%y)return 0;
	int tmp=std::lower_bound(id+1,id+tot+1,x/y)-id;
	return g[tmp];
}
void init(){
	for(int i=1;i<=13;++i)que.emplace(i);
	for(;que.size();){
		int x=que.top();que.pop();
		if(x>lim||mp[x])continue;;mp[x]=1;
		id[++tot]=x;
		que.emplace(x*2ll);que.emplace(x*3ll);que.emplace(x*5ll);que.emplace(x*7ll);
	}
}
signed main(){
	read(f[0],g[0],T,mod);
	for(int i=1;i<=13;++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]);
	}
	for(int i=13;i;--i)f[i]=f[i]-f[i-1],g[i]=g[i]-g[i-1];
	init();
	for(int i=14;i<=tot;++i){
		f[i]=(get_g(id[i],2)+get_g(id[i],3)+get_g(id[i],5)+get_g(id[i],7))%mod;
		g[i]=(get_f(id[i],2)+get_f(id[i],3)+get_f(id[i],4)+get_f(id[i],5))%mod;
	}
	for(int i=1;i<=tot;++i)(f[i]+=f[i-1])%=mod,(g[i]+=g[i-1])%=mod;
	for(;T--;){
		int x;read(x);
		int tmp=std::upper_bound(id+1,id+tot+1,x)-id-1;
		write(f[tmp],' ',g[tmp],'\n');
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 99ms
memory: 16268kb

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: 95ms
memory: 12172kb

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: 103ms
memory: 13984kb

input:

2023 2023 10 2023
0
1
2
3
4
5
6
7
8
9

output:

2023 2023
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

result:

wrong answer 1st numbers differ - expected: '0', found: '2023'