QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370489#5045. Kingzzuqy#WA 301ms9316kbC++112.2kb2024-03-29 09:38:282024-03-29 09:40:01

Judging History

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

  • [2024-03-29 09:40:01]
  • 评测
  • 测评结果:WA
  • 用时:301ms
  • 内存:9316kb
  • [2024-03-29 09:38:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long read()
{
    long long x;scanf("%lld",&x);return x;
}
ll quick(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=ans*a%mod;
        b=b/2;
        a=a*a%mod;
    }
    return ans;
}
ll a[200010],n,p;
map<int,int>id;//表示
vector<int>pos[200010];
int ask1()
{
    int x=(1ll*rand()*rand()+rand())%n+1;
    while(x==n)
        x=(1ll*rand()*rand()+rand())%n+1;
    int y=min(n,x+1ll);
    int q=a[y]*quick(a[x],p-2,p);
    int qq=quick(q,p-2,p);
    int len=2;
    while(x!=1)//往前跳
    {
        ll v=id[a[x]*qq%p];
        if(v==0||pos[v][0]>=x)
            break;
        len++;
        x=*(lower_bound(pos[v].begin(),pos[v].end(),x)-1);

    }
    while(y!=n)
    {
        ll v=id[a[y]*q%p];
        if(v==0||pos[v].back()<=y)
            break;
        len++;
        y=*upper_bound(pos[v].begin(),pos[v].end(),y);
    }
    return len;
}
int ask2()
{
    int x=(1ll*rand()*rand()+rand())%n+1;
    while(x==n)
        x=(1ll*rand()*rand()+rand())%n+1;
    int y=min(n,x+2ll);
    int q=a[y]*quick(a[x],p-2,p);//
    int qq=quick(q,p-2,p);
    int len=2;
    while(x!=1)//往前跳
    {
        ll v=id[a[x]*qq%p];
        if(v==0||pos[v][0]>=x)
            break;
        len++;
        x=*(lower_bound(pos[v].begin(),pos[v].end(),x)-1);

    }
    while(y!=n)
    {
        ll v=id[a[y]*q%p];
        if(v==0||pos[v].back()<=y)
            break;
        len++;
        y=*upper_bound(pos[v].begin(),pos[v].end(),y);
    }
    return len;
}
void work()
{
    n=read();p=read();
    id.clear();
    int sum=0;
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    for(int i=1;i<=n;i++)
    {
        if(id[a[i]]==0)
        {
            sum++;
            id[a[i]]=sum;
            pos[sum].push_back(i);
        }
    }
    int ans=-1;
    for(int i=1;i<=200;i++)
        ans=max(ans,ask1()),ans=max(ans,ask2());
    if(ans*2<n)
        ans=-1;
    cout<<ans<<'\n';
    for(int i=1;i<=sum;i++)
        pos[i].clear();
}
int main()
{
    srand(time(0));
    for(int t=read();t;t--)
        work();
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8488kb

input:

4
6 1000000007
1 1 2 4 8 16
6 1000000007
597337906 816043578 617563954 668607211 89163513 464203601
5 1000000007
2 4 5 6 8
5 1000000007
2 4 5 6 7

output:

5
-1
3
-1

result:

ok 4 number(s): "5 -1 3 -1"

Test #2:

score: -100
Wrong Answer
time: 301ms
memory: 9316kb

input:

1000
200 495189361
193302375 262009153 248101278 250233641 303504256 426913173 23261177 206011896 214770731 286184509 492688635 207979481 282629026 450810670 41818047 359796006 445343921 241742611 249404909 41291916 392252331 125287519 92825425 162555413 371172157 420486666 270651384 309213995 11709...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 2nd numbers differ - expected: '133', found: '-1'