QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602459 | #9426. Relearn through Review | ILoveuhiuhiu | WA | 186ms | 3632kb | C++14 | 2.4kb | 2024-10-01 01:30:59 | 2024-10-01 01:30:59 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
const ll inf = 1e18;
const long double esp=1e-12;
const ll mod=1e9+7;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
vector<ll> fr;
vector<ll> st;
void build(int id,int l,int r) {
if (l == r) {
st[id] = fr[l];
return;
}
int mid = (l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
st[id] = __gcd(st[id*2],st[id*2+1]);
}
ll get(int id,int l,int r,int u,int v) {
if (v < l || u > r) return 0;
if (u <= l && r <= v) return st[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; cin >> n;
ll k; cin >> k;
vector<ll> a(n+1);
map<ll,int> mpp;
vector<pair<ll,int>> mp;
for (int i=1; i<=n; i++) cin >> a[i];
if (n == 1) {
cout << a[1] + k << endl;
return;
}
ll g = 0;
ll ans = 0;
for (int i=1; i<=n; i++) {
g = __gcd(g,a[i]);
mpp[g] = i;
}
for (auto x: mpp) mp.pb(x);
sort(mp.begin(),mp.end(),greater<pair<ll,int>>());
ans = g;
//cout << g << endl;
vector<ll> fa(n+2,0),fe(n+2,0);
fe[n] = a[n];
fa[1] = a[1];
for (int i=2; i<=n; i++) fa[i] = __gcd(fa[i-1],a[i]);
for (int i=n-1; i>=1; i--) fe[i] = __gcd(fe[i+1],a[i]);
fr.resize(n);
st.resize(4*n);
for (int i=1; i<n; i++) fr[i] = abs(a[i]-a[i+1]);
build(1,1,n-1);
for (int i=1; i<=n; i++) {
ll g1 = __gcd(a[i]+k,fe[i+1]);
ans = max(ans, __gcd(fa[i-1],g1));
if (i >= 2) {
ans = max(ans,__gcd(fa[i-2],__gcd(g1,a[i-1]+k)));
}
}
for (int i=2; i<=n; i++) {
ll g1 = __gcd(a[i]+k,fe[i+1]);
//cout << i << ' ' << g1 << endl;
for (auto x: mp) {
if (x.se <= i-1) {
ll g2 = __gcd(x.fi,get(1,1,n-1,x.se+1,i-1));
ans = max(ans,__gcd(g1,g2));
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int test=1;
cin>>test;
while (test--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: 186ms
memory: 3632kb
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 17th lines differ - expected: '356502546608886970', found: '2'