Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
36303 hi_hi 【S】T1 C++ 编译错误 0 0 MS 0 KB 2060 2025-02-10 20:13:13

Tests(0/0):


#include<bits/stdc++.h> using namespace std; long long n,_,x[10000005],ch[30000006][2],tot,cnt[30000006]; 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); if(n==1){ if(((x[1]^a)-b)*((x[1]^a)-b)<=0){ printf("1\n",); } else printf("-1\n"); } else{ 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"); } } }


测评信息: