QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#857452 | #9426. Relearn through Review | Moemi_ | WA | 173ms | 5740kb | C++20 | 2.5kb | 2025-01-15 18:28:45 | 2025-01-15 18:28:46 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <numeric>
#define sc_int(x) scanf("%d", &x)
#define x first
#define y second
#define pb push_back
using namespace std;
const int N = 1e6 + 10, MOD = 998244353;
const int INF = 1e9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef pair<char, int> PCI;
typedef pair<string, string> PSS;
LL n, m, k;
LL a[N];
struct node
{
int l, r;
LL w;
}tr[N * 4];
void pushup(int u)
{
tr[u].w = __gcd(tr[u << 1].w, tr[u << 1 | 1].w);
}
void build(int u, int l, int r)
{
tr[u] = {l, r};
if(l == r)
{
tr[u].w = abs(a[l]);
return;
}
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
LL query(int u, int l, int r)
{
if(l > r) return 0;
if(tr[u].l >= l && tr[u].r <= r) return tr[u].w;
LL ans = 0;
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) ans = __gcd(ans, query(u << 1, l, r));
if(r > mid) ans = __gcd(ans, query(u << 1 | 1, l, r));
return ans;
}
void solve()
{
cin >> n >> k;
vector<LL> s(n + 1), rs(n + 2);
vector<LL> b(n + 1);
for(int i = 1; i <= n; i ++)
{
cin >> b[i];
a[i] = b[i] - b[i - 1];
// cout << a[i] << " ";
}
// cout << endl;
build(1, 1, n);
vector<int> modify;
for(int i = 1; i <= n; i ++)
{
s[i] = __gcd(s[i - 1], b[i]);
if(s[i] != s[i - 1]) modify.pb(i - 1);
}
// for(auto t : modify) cout << t << " ";
// cout << endl;
for(int i = n; i >= 1; i --) rs[i] = __gcd(rs[i + 1], b[i]);
LL ans = s[n];
for(int i = n; i >= 1; i --)
{
for(auto t : modify)
{
if(t >= i - 1) break;
LL res = query(1, t + 2, i - 1);
res = __gcd(res, __gcd(s[t], rs[i + 1]));
res = __gcd(res, abs(__gcd(a[t + 1] + k, a[i] - k)));
ans = max(ans, res);
}
}
cout << ans << endl;
}
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios::sync_with_stdio(false), 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: 0ms
memory: 5684kb
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: 173ms
memory: 5740kb
input:
100000 1 608611451460421713 33155506392034032 1 743116173559300609 6138108577573005 7 364454564010802125 657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115 4 316648374341335221 365788422120542814 182894211060271407 731...
output:
33155506392034032 6138108577573005 657035115675878115 3 1 98423435849394582 183698346865682381 1 484915690810412536 6 149180825015886938 361813583202892479 915781395066183375 37337367838628559 632093288650732211 377121713907330928 2 494408344393555851 2 2 118387461231999184 1 1 1 809535299113892268 ...
result:
wrong answer 1st lines differ - expected: '641766957852455745', found: '33155506392034032'