QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370505#5045. Kingzzuqy#WA 77ms9016kbC++112.4kb2024-03-29 09:48:442024-03-29 09:48:45

Judging History

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

  • [2024-03-29 09:48:45]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:9016kb
  • [2024-03-29 09:48:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
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)%p;
    ll 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)%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,now=0;
    for(int i=1;i<=1000;i++){
        int t1=ask1(),t2=ask2();
        if(t1==ans)
            now++;
        if(t2==ans)
            now++;
        if(ans!=-1&&now>=6)
            break;
        ans=max(ans,max(t1,t2));
    }
    if(ans*2<n)
        ans=-1;
    cout<<ans<<'\n';
    for(int i=1;i<=sum;i++)
        pos[i].clear();
}
signed 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: 2ms
memory: 9016kb

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: 77ms
memory: 8412kb

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
133
-1
187
163
114
114
132
100
108
116
137
115
-1
165
115
142
165
-1
-1
108
129
-1
144
122
-1
111
146
190
159
134
-1
117
180
196
-1
-1
192
123
110
-1
106
153
103
-1
-1
103
169
-1
174
152
-1
181
113
135
-1
153
199
182
-1
177
152
177
162
-1
115
-1
-1
-1
-1
128
-1
-1
-1
-1
168
167
-1
140
-1
-1
-1
12...

result:

wrong answer 70th numbers differ - expected: '113', found: '-1'