QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623354 | #9426. Relearn through Review | Slink | WA | 138ms | 7752kb | C++14 | 2.3kb | 2024-10-09 11:28:17 | 2024-10-09 11:28:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define int ll
#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));
}
int gcd_3(int a, int b, int c){
return __gcd(a, __gcd(b, c));
}
void solve()
{
int n, k;
cin >> n >> k;
int suf[n + 5] = {}, pre[n + 5];
int ans = 0;
FOR(i, 0, n - 1)
{
cin >> a[i];
ans = __gcd(ans, a[i]);
b[i] = a[i] + k;
}
for(int i = n - 1; i >= 0; --i) suf[i] = __gcd(suf[i + 1], a[i]);
pre[0] = a[0];
for(int i = 1; i < n; ++i) pre[i] = __gcd(pre[i - 1], a[i]);
build(1, 0, n - 1);
for(int r = 0; r < n ; ++r)
{
int x = get(1, 0, n - 1, 0, r);
ans = max(ans, __gcd(x, suf[r + 1]));
}
FOR(l, 1, n - 1)
{
int lo = l, hi = n - 1, r = n - 1;
while (lo <= hi)
{
int mid = (lo + hi) / 2;
if (suf[mid + 1] % pre[l - 1])
{
lo = mid + 1;
}
else
{
if (suf[mid + 1] % pre[l - 1] == 0)
{
r = mid;
hi = mid - 1;
}
else
lo = mid + 1;
}
}
int x = gcd_3(pre[l - 1], get(1, 0, n - 1, l, r), suf[r + 1]);
ans = max(ans, x);
//cout << l << ' ' << r << ' ' << get(1, 0, n - 1, l, r) << ' ' << pre[l - 1] << ' ' << suf[r + 1] << ' ' << x << endl;
}
cout << ans << endl;
}
signed 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: 7740kb
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: 138ms
memory: 7752kb
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'