QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647201#9426. Relearn through ReviewcyanacWA 179ms9292kbC++201.9kb2024-10-17 12:39:042024-10-17 12:39:05

Judging History

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

  • [2024-10-17 12:39:05]
  • 评测
  • 测评结果:WA
  • 用时:179ms
  • 内存:9292kb
  • [2024-10-17 12:39:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+10;
int f[N][22],f1[N][22];
int lo[N];
int query(int l,int r)
{
    int len=r-l+1;
    int k=lo[len];
    return gcd(f[l][k],f[r+1-(1<<k)][k]);

}
int query1(int l,int r)
{
    int len=r-l+1;
    int k=lo[len];
    return gcd(f1[l][k],f1[r+1-(1<<k)][k]);
}
int val(int l,int r)
{
    int res=0;
    for(int i=l;i<r;i++)
    {
        res=max(res,gcd(query1(l,i),query(i+1,r)));

    }
    res=max(res,query1(l,r));
    return res;
}
void solve()
{
    //cout<<(1<<22)<<endl;
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1,0),b(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=a[i]+k;
    }
    for(int j=0;j<22;j++)
    {
        for(int i=1;i+(1<<j)-1<=n;i++)
        {
            if(!j)
            {
                f[i][j]=a[i];
                f1[i][j]=b[i];
            }
            else
            {
                f[i][j]=gcd(f[i][j-1],f[i+(1<<j-1)][j-1]);
                f1[i][j]=gcd(f1[i][j-1],f1[i+(1<<j-1)][j-1]);
            }
        }
    }
    int sum=0;
    int pre=0,prepos=-1;
    int ans=query(1,n);
    ans=max(query1(1,n),ans);
    for(int i=1;i<=n;i++)
    {
        // if(i==1)
        // {
        //     sum=gcd(sum,a[i]);
        //     pre=sum;
        //     prepos==1;
        //     continue;

        // }
        if(gcd(sum,a[i])==pre)
        {
            prepos=i;
        }
        else
        {
            int t=val(i,n);
            ans=max(ans,gcd(query(1,prepos),t));
            pre=gcd(sum,a[i]);
            prepos=i;
        }


    }

    cout<<ans<<endl;

}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
     for(int i = 2; i <N; i++) lo[i] = lo[i >> 1] + 1;
    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: 8784kb

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: 179ms
memory: 9292kb

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
1
962990836390050009
616597869896951268
878097339332572161
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
1
356502546608886970
789177332497...

result:

wrong answer 7th lines differ - expected: '183698346865682381', found: '1'