QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269648#7749. A Simple MST ProblemHayasaTL 862ms140652kbC++20994b2023-11-29 20:51:282023-11-29 20:51:29

Judging History

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

  • [2023-11-29 20:51:29]
  • 评测
  • 测评结果:TL
  • 用时:862ms
  • 内存:140652kb
  • [2023-11-29 20:51:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int M=1e6+10;

int dis[M],mn[M];
bool mk[M];
vector<int>G[M];
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	vector<int>w(M);
	for(int i=2;i<=1e6;++i)if(!w[i])
	   	for(int j=i;j<=1e6;j+=i)w[j]++;
	for(int i=1;i<=1e6;++i)
		for(int j=i;j<=1e6;j+=i)
			G[j].emplace_back(i);
	for(int i=1;i<=1e6;++i)mn[i]=dis[i]=1e9;

	int q;
	scanf("%d",&q);
	priority_queue<pair<int,int>>que;
	while(q--){
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=0;
		que.emplace(0,l);
		dis[l]=0;
		while(!que.empty()){
			auto [d,x]=que.top();
			que.pop();
			if(mk[x])continue;
			ans+=dis[x],mk[x]=1;
			for(int y:G[x]){
				if(mn[y]>w[x]){
					mn[y]=w[x];
					for(int i=((l-1)/y+1)*y;i<=r;i+=y){
						if(mk[i])continue;
						if(dis[i]>w[i]+w[x]-w[y]){
							dis[i]=w[i]+w[x]-w[y];
							que.emplace(-dis[i],i);
						}
					}
				}
			}
		}
		for(int i=l;i<=r;++i){
			dis[i]=1e9,mk[i]=0;
			for(int x:G[i])mn[x]=1e9;
		}
		printf("%d\n",ans);
	}
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 661ms
memory: 129952kb

input:

5
1 1
4 5
1 4
1 9
19 810

output:

0
2
3
9
1812

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 652ms
memory: 132444kb

input:

2
27 30
183704 252609

output:

8
223092

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 685ms
memory: 132220kb

input:

1
183704 252609

output:

223092

result:

ok single line: '223092'

Test #4:

score: 0
Accepted
time: 862ms
memory: 138688kb

input:

2
639898 942309
30927 34660

output:

983228
11512

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 835ms
memory: 140652kb

input:

3
21731 33468
46192 370315
1712 3753

output:

34608
948775
5299

result:

ok 3 lines

Test #6:

score: 0
Accepted
time: 709ms
memory: 134724kb

input:

4
15237 67700
10918 86104
98287 116980
17432 23592

output:

148811
210927
60893
18687

result:

ok 4 lines

Test #7:

score: -100
Time Limit Exceeded

input:

5
5594 70302
19202 69588
5634 7877
59821 469300
97439 261121

output:

179735
145706
6565
1203684
488669

result: