QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#680442 | #9426. Relearn through Review | HTensor# | WA | 190ms | 3844kb | C++23 | 2.1kb | 2024-10-26 21:04:40 | 2024-10-26 21:04:41 |
Judging History
answer
#include <bits/stdc++.h>
#define dd(x) cout << #x << "\n"
#define d(x) cout << #x << ": " << x << "\n"
#define SZ(x) ((int)(x).size())
using namespace std;
#define int long long
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vii = vector<vector<int>>;
using a3 = array<int, 3>;
using ll = long long;
const int inf = 0x3f3f3f3f3f3f3f3fLL;
#define MULTI_TEST
void solve() {
int n, k; cin >> n >> k;
vector<int> a(n + 1), pr(n + 1), ed(n + 2), nxt(n + 2);
vector f(n + 1, vector<int> (20));
vector<int> logx(n + 1);
for(int i = 2; i <= n; i++) logx[i] = logx[i / 2] + 1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
f[i][0] = abs(a[i] - a[i - 1]);
pr[i] = gcd(pr[i - 1], a[i]);
}
for(int j = 1; j < 20; j++) {
for(int i = 1; i + (1 << (j - 1)) <= n; i++) {
f[i][j] = gcd(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
}
}
auto rg = [&](int l, int r) {
if(l > r) return 0LL;
int len = r - l + 1;
return gcd(f[l][logx[len]], f[r - (1 << logx[len]) + 1][logx[len]]);
};
for(int i = n; i; i--) {
ed[i] = gcd(ed[i + 1], a[i]);
if(ed[i] != ed[i + 1]) {
nxt[i] = i + 1;
} else {
nxt[i] = nxt[i + 1];
}
}
nxt[n + 1] = n + 2;
int ans = rg(1, n);
for(int l = 1; l <= n; l++) {
ans = max(ans, gcd(
gcd(pr[l - 1], a[l] + k),
ed[l + 1]
));
int gcdv = gcd(pr[l - 1], a[l] + k);
int r = nxt[l + 1] - 1;
while(r <= n) {
ans = max(ans, gcd(
gcdv, gcd(
rg(l + 1, r), ed[r + 1]
)
));
r = nxt[r];
}
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
#ifdef MULTI_TEST
int T; cin >> T;
#else
int T = 1;
#endif
while(T--) solve();
return 0;
}
/*
1
7 8
1 6 6 6 12 12 48
2
6 2
5 3 13 8 10 555
3 0
3 6 9
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3836kb
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: 190ms
memory: 3844kb
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 200th lines differ - expected: '151390338255159315', found: '1'