QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625971#9426. Relearn through ReviewORZZZWA 160ms5732kbC++141.6kb2024-10-09 22:06:522024-10-09 22:06:52

Judging History

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

  • [2024-10-09 22:06:52]
  • 评测
  • 测评结果:WA
  • 用时:160ms
  • 内存:5732kb
  • [2024-10-09 22:06:52]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define gcd __gcd
#define int long long

using namespace std;

const int N = 3e5 + 10;
int a[N], g[N][20];

int get(int l, int r){
	int k =  31 - __builtin_clz(r - l + 1);
	return gcd(g[l][k], g[r - (1 << k) + 1][k]);
}

int gcd_3(int a, int b, int c){
	return gcd(a, gcd(b, c));
}

void solve(){
	int n, k; cin >> n >> k;
	
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		g[i][0] = a[i] + k;
		ans = gcd(a[i], ans);
	}

	int pre[n + 5] = {}, suf[n + 5] = {};
	for(int i = 1; i <= n; ++i) pre[i] = gcd(pre[i - 1], a[i]);
	for(int i = n; i >= 1; --i) suf[i] = gcd(suf[i + 1], a[i]);

	for(int j = 1; j <= 20; ++j){
		for(int i = 1; i + (1 << j) - 1 <= n; ++i){
			g[i][j] = gcd(g[i][j - 1], g[i + (1 << (j - 1))][j - 1]);
		}
	}
	

	for(int r = 1; r <= n; ++r){
		ans = max(ans, gcd(get(1, r), suf[r + 1]));
	}

	for(int l = 2; l <= n; ++l){	
		int lo = l, hi = n, r = n;
		while(lo <= hi){
			int mid = (lo + hi) / 2;
			if(suf[mid + 1] % pre[l - 1]){
				lo = mid + 1;
			}
			else{
				r = mid;
				hi = mid - 1;
			}
		}
		if(r != n) ans = max(ans, gcd_3(pre[l - 1], suf[r + 1], get(l, r)));
		else{
			for(int R = n; R >= max(l, R - 100); --R)
				ans = max(ans, gcd_3(pre[l - 1], suf[R + 1], get(l, R)));
			for(int R = l; R <= min(l + 100, n); ++R)
				ans = max(ans, gcd_3(pre[l - 1], suf[R + 1], get(l, R)));
		}
	}
	cout << ans << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5732kb

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 160ms
memory: 5616kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

641766957852455745
749254282136873614
657035115675878115
182894211060271407
880411769063535667
560553564512176618
183698346865682381
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
3771217139073309...

result:

wrong answer 62nd lines differ - expected: '493288591409539188', found: '6'