QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788088#9669. Function Queryship2077WA 0ms5940kbC++231.2kb2024-11-27 15:53:422024-11-27 15:53:42

Judging History

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

  • [2024-11-27 16:16:04]
  • hack成功,自动添加数据
  • (/hack/1261)
  • [2024-11-27 15:53:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5940kb
  • [2024-11-27 15:53:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=3e5+5;map<int,int>mp;
int n,q,idx,ans,x[M],tr[M*30][4],cur[M*30];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
void insert(int x,int y,int id){
    int p=1;
    for (int i=30;~i;i--){
        int ch=((x>>i&1)<<1)|(y>>i&1);
        if (!tr[p][ch]) tr[p][ch]=++idx;
        p=tr[p][ch];
    } cur[p]=id;
}
void query(int p,int a,int b,int d=30){
    if (ans!=-1||!p) return;
    if (d<0) return ans=cur[p],void();
    const int A=a>>d&1,B=b>>d&1;
    for (int i=0;i<2;i++)
        for (int j=0;j<2;j++)
            if ((A^i)<=B&&B<=(A^j))
                query(tr[p][i<<1|j],a,b,d-1);
}
int main(){
    n=read();q=read();idx=1;
    for (int i=1;i<=n;i++) x[i]=read(),mp[x[i]]=i;
    for (int i=1;i<n;i++) insert(x[i],x[i+1],i),insert(x[i+1],x[i],i);
    for (int i=1;i<=q;i++){
        int a=read(),b=read();ans=-1;
        if (mp.count(a^b)) ans=mp[a^b]; query(1,a,b);
        assert(ans==-1||(1ll*(x[ans]^a)-b)*((x[ans+1]^a)-b)<=0);
        printf("%d\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 6
3 5 1 2 4
0 2
1 1
2 3
3 2
4 2
5 8

output:

4
3
3
3
4
-1

result:

ok ok

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3796kb

input:

2 1
3 3
0 3

output:

2

result:

wrong answer Integer parameter [name=pans] equals to 2, violates the range [-1, 1]