UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199012#3463. 最大区间FinderHT1004780ms32436kbC++111.3kb2023-12-03 11:39:312023-12-03 12:28:32

answer

#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define int long long
#define ull unsigned long long
#define fst first
#define snd second
#define mkp(x,y) make_pair(x,y)
#define L(x) x<<1
#define R(x) x<<1|1
using namespace std;
typedef pair<int,int> pii;
const double eps=1e-6;
inline bool pts(char ch){return ch>=48&&ch<=57;}
inline int read(){
	bool f=0;int x=0;char ch;
	ch=gt();
	while(!pts(ch)&&ch!=EOF){if(ch=='-')f=1;ch=gt();}
	while(pts(ch)){x*=10;x+=(ch-48);ch=gt();}
	if(f)return -x;
	else return x;
}
template<class T>
inline void print(T x){
	char s[114];
	int top=0;
	if(x<0)pt('-');
	do{
		top++;
		if(x>=0)s[top]=(x%10)+48;
		else s[top]=(-(x%10)+48);
		x/=10;
	}while(x);
	while(top){pt(s[top]);top--;}
}
struct segment{int l,r;};
bool operator<(segment a,segment b){if(a.l!=b.l)return a.l>b.l;else return a.r>b.r;}
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
priority_queue<pair<int,segment> >h;
int a[1000005];
signed main(){
	int n=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		segment tmp={i,i};
		h.push(mkp(a[i],tmp));
	}
	while(k--){
		auto top=h.top();
		h.pop();
		cout<<top.fst<<'\n';
		if(top.snd.r+1<=n){
			segment tmp={top.snd.l,top.snd.r+1};
			h.push(mkp(gcd(top.fst,a[top.snd.r+1]),tmp));
		}
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 162ms
memory: 1264kb

input:

1000 500500
316229930 195440845 285 190 173850 107445 48194844915 29786052240 3470662866825 21449876...

output:

26383670221365600
16306004944772400
8332780503682635
7971077017640880
7253015614619775
5149941572068...

result:

ok 500500 lines

Test #2:

score: 10
Accepted
time: 150ms
memory: 1264kb

input:

1000 500500
10 5 45 30 3705 2280 452880675 279895650 18411000 11378625 13430625 8300625 6940498125 4...

output:

13694362219137600
12805411076655120
12463020406156320
8463581305679500
7914179285287275
770257021348...

result:

ok 500500 lines

Test #3:

score: 10
Accepted
time: 79ms
memory: 1264kb

input:

1000 500500
2571145 1589055 7945275 4910450 3557450 2198625 75348000 46567625 4922125 3042000 940062...

output:

36372051035345025
22479163780389030
13119152823571600
10459936245458700
8108082348571400
74488088766...

result:

ok 500500 lines

Test #4:

score: 10
Accepted
time: 517ms
memory: 4668kb

input:

100000 1000000
269019726702209411 974764215496813081 547920080673102149 403277729561219907 575984909...

output:

999997745191855356
999963005393234573
999926113482756345
999922932458629212
999873551825672168
99986...

result:

ok 1000000 lines

Test #5:

score: 10
Accepted
time: 278ms
memory: 4664kb

input:

100000 1000000
269845965585325539 410993175365329221 287854792412106895 411389931291882089 384766635...

output:

999984587617809411
999982422426861182
999977862966742257
999962389243327312
999960196509914341
99995...

result:

ok 1000000 lines

Test #6:

score: 10
Accepted
time: 301ms
memory: 4668kb

input:

100000 1000000
270672213058376259 847222126643910770 251161541005887448 196130104757703054 970176324...

output:

999969088094752736
999950043867991957
999942757941147478
999938229401659037
999937972040991874
99993...

result:

ok 1000000 lines

Test #7:

score: 10
Accepted
time: 791ms
memory: 32436kb

input:

1000000 1000000
445 275 2160 1335 9345 5775 1969065 1216950 2742977370 1695253245 1295058240 8003900...

output:

975897643491928749
967909511887184303
957662363896634201
937776145086931820
935483120267844976
93449...

result:

ok 1000000 lines

Test #8:

score: 10
Accepted
time: 928ms
memory: 32432kb

input:

1000000 1000000
120789085 74651760 373258800 230686625 3751250 2318400 437094650 270139350 72250 433...

output:

989440590200479888
979442127462649963
962123363113843633
949234663940571975
922027929185254986
91132...

result:

ok 1000000 lines

Test #9:

score: 10
Accepted
time: 815ms
memory: 32436kb

input:

1000000 1000000
511670775 316229930 275 165 1493195 922845 24310 12155 3843774799150 2375583470975 4...

output:

993470386599911223
982929594264450702
981834284237042557
980913038932188165
977556796318907338
96567...

result:

ok 1000000 lines

Test #10:

score: 10
Accepted
time: 759ms
memory: 32436kb

input:

1000000 1000000
4131543 2553434 22615848255 13977362906 63648 39338 26483679092 16367813826 766428 4...

output:

996943230476562837
992744165900993793
977870523681018327
973905575456964502
971181334873983918
94411...

result:

ok 1000000 lines

Extra Test:

score: 0
Extra Test Passed