QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602449#9426. Relearn through ReviewILoveuhiuhiuWA 183ms3672kbC++142.3kb2024-10-01 01:19:042024-10-01 01:19:06

Judging History

你现在查看的是最新测评结果

  • [2024-10-01 01:19:06]
  • 评测
  • 测评结果:WA
  • 用时:183ms
  • 内存:3672kb
  • [2024-10-01 01:19:04]
  • 提交

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> mp;
    for (int i=1; i<=n; i++) cin >> a[i];
    if (n == 1) {
        cout << a[0] + k << endl;
        return;
    }
    ll g = 0;
    ll ans = 0;
    for (int i=1; i<=n; i++) {
        g = __gcd(g,a[i]);
        mp[g] = i;
    }
    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: 3560kb

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: 183ms
memory: 3672kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

608611451460421713
743116173559300609
657035115675878115
182894211060271407
880411769063535667
462130128662782036
183698346865682381
962990836390050009
131682179086538732
878097339332572161
39640169659457590
997057718507559252
33292984544308075
37337367838628559
632093288650732211
377121713907330928...

result:

wrong answer 1st lines differ - expected: '641766957852455745', found: '608611451460421713'