Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
36301 | hi_hi | 【S】T1 | C++ | 运行出错 | 58 | 918 MS | 398248 KB | 1813 | 2025-02-10 20:09:04 |
#include<bits/stdc++.h> using namespace std; long long n,_,x[10000005],ch[10000006][2],tot,cnt[10000006]; inline string nm_01(long long x){ string s,_; while(x!=0){ s+=(x%2+'0'); x/=2; } _=s; for(int i=0;i<s.length();i++){ _[i]=s[s.length()-i-1]; } while(_.length()<30)_="0"+_; return _; } inline long long c(char a){ if(a=='1')return 1; return 0; } inline void j(string s,long long x){ long long p=0; long long l=s.length(); for(int i=0;i<l;i++){ if(ch[p][c(s[i])]==0)ch[p][c(s[i])]=++tot; p=ch[p][c(s[i])]; } cnt[p]=x; } inline long long fdl(string s){ long long p=0; long long l=s.length(); for(int i=0;i<l;i++){ long long t; if(c(s[i])==0)t=1; else t=0; if(ch[p][c(s[i])]==0)p=ch[p][t]; else p=ch[p][c(s[i])]; } return cnt[p]; } inline long long fdr(string s){ long long p=0; long long l=s.length(); for(int i=0;i<l;i++){ long long t; if(c(s[i])==0)t=1; else t=0; if(ch[p][t]==0)p=ch[p][c(s[i])]; else p=ch[p][t]; } return cnt[p]; } int main(){ scanf("%lld%lld",&n,&_); for(long long i=1;i<=n;i++){ scanf("%lld",&x[i]); j(nm_01(x[i]),i); } while(_--){ long long a,b; scanf("%lld%lld",&a,&b); long long l=fdl(nm_01(a)); long long r=fdr(nm_01(a)); if(((x[l]^a)-b)*((x[r]^a)-b)<=0){ long long ll=min(l,r),rr=max(l,r); while(ll<rr){ if(ll==rr-1)break; long long mid=(ll+rr)/2; if(((x[ll]^a)-b)*((x[mid]^a)-b)<=0)rr=mid; else ll=mid; } printf("%lld\n",ll); } else printf("-1\n"); } }