QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625847 | #9426. Relearn through Review | ORZZZ | TL | 1594ms | 5984kb | C++14 | 1.5kb | 2024-10-09 21:24:23 | 2024-10-09 21:24:24 |
Judging History
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 l = 1; l <= n; ++l){
for(int r = l; r <= n; ++r) ans = max(ans, gcd_3(pre[l - 1], get(l, r), suf[r + 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;
// }
// }
// 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: 5692kb
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: 0
Accepted
time: 144ms
memory: 5636kb
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:
ok 100000 lines
Test #3:
score: 0
Accepted
time: 1594ms
memory: 5984kb
input:
1000 71 451750502977198411 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 701513700102652904 7015137...
output:
701513700102652904 628264251002959880 866034990978685601 718723820869997225 525309136656747615 453291245761058554 420366973911241294 500173849665919725 16701821680586640 794711320668492112 799961738480944637 963500289005941882 190368877908873112 973069943210898565 629019279628092667 1921616220783983...
result:
ok 1000 lines
Test #4:
score: -100
Time Limit Exceeded
input:
100 5516 16561406822518327 121909691713696369 226403713182578971 940446193219943418 505054437099599243 505054437099599243 383144745385902874 470223096609971709 714042480037364447 417976085875530408 783705161016619515 888199182485502117 208988042937765204 330897734651461573 818536501506247049 7488738...