QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623109 | #9426. Relearn through Review | Slink | WA | 8ms | 5704kb | C++14 | 2.0kb | 2024-10-09 10:13:09 | 2024-10-09 10:13:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define vi vector<int>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FOD(i, a, b) for (int i = a; i >= b; --i)
const int N = 3e5 + 10;
int a[N], b[N], g[N * 4];
void build(int id, int l, int r)
{
if (l == r)
{
g[id] = b[l];
return;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
g[id] = __gcd(g[id * 2], g[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
if (r < u || l > v)
return 0;
if (u <= l && r <= v)
return g[id];
int mid = (l + r) / 2;
return __gcd(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
void solve()
{
int n, k;
cin >> n >> k;
int suf[n + 5] = {};
int ans = 0;
FOR(i, 0, n - 1)
{
cin >> a[i];
ans = __gcd(ans, a[i]);
b[i] = a[i] + k;
}
FOD(i, n - 1, 0) suf[i] = __gcd(suf[i + 1], a[i]);
build(1, 0, n - 1);
FOR(r, 0, n - 1)
{
int x = get(1, 0, n - 1, 0, r);
ans = max(ans, __gcd(x, suf[r + 1]));
}
int gcd_left = a[0];
FOR(l, 1, n - 1)
{
int lo = l, hi = n - 1, r = -1;
while (lo <= hi)
{
int mid = (lo + hi) / 2;
if (suf[mid + 1] % gcd_left)
{
lo = mid + 1;
}
else
{
if (suf[mid + 1] % gcd_left == 0)
{
r = mid;
hi = mid - 1;
}
else
lo = mid + 1;
}
}
ans = max(ans, __gcd(gcd_left, __gcd(get(1, 0, n - 1, l, r), suf[r + 1])));
gcd_left = __gcd(gcd_left, a[l]);
}
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5704kb
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: 8ms
memory: 5696kb
input:
100000 1 608611451460421713 33155506392034032 1 743116173559300609 6138108577573005 7 364454564010802125 657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115 4 316648374341335221 365788422120542814 182894211060271407 731...
output:
2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 214...
result:
wrong answer 1st lines differ - expected: '641766957852455745', found: '2147483647'