QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721023#9426. Relearn through ReviewAlasco#WA 116ms7968kbC++141.8kb2024-11-07 15:00:162024-11-07 15:00:18

Judging History

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

  • [2024-11-07 15:00:18]
  • 评测
  • 测评结果:WA
  • 用时:116ms
  • 内存:7968kb
  • [2024-11-07 15:00:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int n,L[105],R[105],cl,cr;
ll k,a[300005],gl[300005],gr[300005],st[300005][22],ans;
ll find(int l,int r){
    if(r<l){
        return 0;
    }
    int t=log(r-l+1)/log(2);
    // cout<<"LOG"<<r<<" "<<l<<" "<<r-l+1<<" "<<t<<"\n";
    return __gcd(st[l][t],st[r-(1<<t)+1][t]);
}
void __(){
    cin>>n>>k;
    ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ans=__gcd(ans,a[i]);
        st[i][0]=a[i]+k;
        gl[i]=__gcd(gl[i-1],a[i]);
    }
    gr[n+1]=0;
    for(int i=n;i>=1;i--){
        gr[i]=__gcd(gr[i+1],a[i]);
    }
    cl=0;
    cr=0;
    for(int i=1;i<n;i++){
        if(gl[i]!=gl[i+1]){
            L[++cl]=i;
        }
        if(gr[i]!=gr[i+1]){
            R[++cr]=i+1;
        }
    }
    
    for(int i=1;i<=20;i++){
        for(int j=1;j+(1<<(i-1))<=n;j++){
            st[j][i]=__gcd(st[j][i-1],st[j+(1<<(i-1))][i-1]);
        }
    }
    // cout<<"A\n";
    // for(int i=1;i<=n;i++){
    //     cout<<gl[i]<<" ";
    // }
    // cout<<"\n";
    // for(int i=1;i<=n;i++){
    //     cout<<gr[i]<<" ";
    // }
    // cout<<"\n";
    // for(int i=1;i<=cl;i++){
    //     cout<<L[i]<<" ";
    // }
    // cout<<"\n";
    // for(int i=1;i<=cr;i++){
    //     cout<<R[i]<<" ";
    // }
    // cout<<"\n";
    // cout<<"B\n";
    
    for(int i=1;i<=cl;i++){
        for(int j=1;j<=cr;j++){
            if(L[i]>=R[j]-1){
                continue;
            }
            ll tmp=__gcd(find(L[i]+1,R[j]-1),__gcd(gl[L[i]],gr[R[j]]));
            ans=max(ans,tmp);
            // cout<<"FIND"<<L[i]<<" "<<R[j]<<" "<<find(L[i]+1,R[j]-1)<<"\n";
        }
    }
    // cout<<"ans";
    cout<<ans<<"\n";
}
int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr);
    int _;cin>>_;while(_--)__();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7968kb

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: 116ms
memory: 7964kb

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
1
1
484915690810412536
3
149180825015886938
361813583202892479
915781395066183375
37337367838628559
632093288650732211
1
2
494408344393555851
1
1
118387461231999184
1
1
1
809535299113892268
580787185875674097
3
4435168108152...

result:

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