QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788095#9669. Function Queryship2077WA 73ms5836kbC++231.2kb2024-11-27 15:55:042024-11-27 15:55:04

Judging History

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

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

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();
    for (int i=1;i<n;i++) mp[x[i]]=mp[x[i+1]]=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: 1ms
memory: 5836kb

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: 0
Accepted
time: 0ms
memory: 3788kb

input:

2 1
3 3
0 3

output:

1

result:

ok ok

Test #3:

score: -100
Wrong Answer
time: 73ms
memory: 5004kb

input:

300000 300000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

89695
-1
119478
149700
119478
269763
59791
89695
119478
-1
179614
299999
239765
89695
-1
59791
269763
179614
179614
209610
209610
209610
-1
119478
239765
299999
89695
179614
89695
269763
239765
-1
59791
-1
299999
89695
149700
-1
179614
59791
59791
89695
89695
59791
179614
179614
179614
59791
-1
2397...

result:

wrong answer participant gave a wrong answer