QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#788140 | #9669. Function Query | ship2077 | RE | 238ms | 6996kb | C++23 | 1.4kb | 2024-11-27 16:02:46 | 2024-11-27 16:02:46 |
Judging History
This is the latest submission verdict.
- [2024-11-27 16:16:04]
- hack成功,自动添加数据
- (/hack/1261)
- [2024-11-27 16:02:46]
- Submitted
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 tmpa,int tmpb,int d=30){
if (ans!=-1||!p) return;
if (d<0) return ans=cur[p],void();
const int A=a>>d,B=b>>d;
tmpa<<=1;tmpb<<=1;
for (int i=0;i<2;i++)
for (int j=0;j<2;j++)
if ((A^(tmpa|i))<=B&&B<=(A^(tmpb|j)))
query(tr[p][i<<1|j],a,b,tmpa|i,tmpb|j,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++) 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;
// for (int j=1;j<n;j++){
// if ((x[j]^a)<=b&&b<=(x[j+1]^a)) {ans=j;break;}
// if ((x[j+1]^a)<=b&&b<=(x[j]^a)) {ans=j;break;}
// }
if (mp.count(a^b)) ans=mp[a^b]; query(1,a,b,0,0);
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: 3816kb
input:
5 6 3 5 1 2 4 0 2 1 1 2 3 3 2 4 2 5 8
output:
3 3 3 3 2 -1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 5996kb
input:
2 1 3 3 0 3
output:
1
result:
ok ok
Test #3:
score: 0
Accepted
time: 149ms
memory: 5864kb
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:
59791 209610 89695 89695 89695 269763 29721 59791 89695 209610 149700 209610 209610 59791 -1 29721 209610 89695 149700 89695 89695 149700 209610 89695 209610 269763 59791 89695 59791 209610 209610 209610 29721 89695 209610 59791 89695 89695 149700 29721 29721 59791 59791 29721 149700 149700 149700 2...
result:
ok ok
Test #4:
score: 0
Accepted
time: 147ms
memory: 6356kb
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:
59824 29872 239818 120024 269973 120024 209816 120024 29871 120024 120024 29872 179677 209816 90063 90063 59824 29872 209816 120024 59824 209816 120024 149876 179677 59824 29871 149876 120024 149876 59824 269973 209816 179677 29871 120024 239818 149876 179677 29872 239818 29872 149876 149876 120024 ...
result:
ok ok
Test #5:
score: 0
Accepted
time: 165ms
memory: 6316kb
input:
299999 300000 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999...
output:
59912 59912 59912 89929 59912 59912 59912 59912 30017 59912 269781 59912 59912 149833 89929 89929 179888 59912 149833 -1 239680 59912 59912 59912 269781 59912 59912 59912 59912 30017 269781 89929 59912 59912 59912 59912 269781 149833 59912 59912 59912 30018 30017 179888 30018 59912 59912 59912 59912...
result:
ok ok
Test #6:
score: 0
Accepted
time: 168ms
memory: 5120kb
input:
299999 300000 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999990 999999...
output:
149501 149501 59597 59597 149501 89750 89750 59597 179553 59597 29668 59597 269967 149501 149501 59597 59597 59597 59597 59597 59597 269967 59597 59597 269967 209808 179553 269967 59597 59597 59597 59597 59597 89750 149501 89750 269967 59597 59597 59597 269967 29667 209808 59597 29668 59597 59597 14...
result:
ok ok
Test #7:
score: 0
Accepted
time: 146ms
memory: 6076kb
input:
300000 300000 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ...
output:
24072 62885 -1 153067 153067 62885 -1 162026 62885 -1 -1 108288 50934 153067 -1 153067 -1 50934 -1 -1 153067 24072 62885 153067 153067 -1 168096 -1 -1 11995 -1 -1 30177 -1 20999 39023 -1 20999 210256 233864 269855 -1 62885 -1 -1 65877 -1 50934 -1 153067 -1 62885 39023 -1 -1 62885 -1 257912 -1 -1 -1 ...
result:
ok ok
Test #8:
score: 0
Accepted
time: 143ms
memory: 6580kb
input:
300000 300000 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ...
output:
153157 -1 -1 -1 -1 80636 281910 -1 201058 132105 -1 65745 245980 -1 2965 -1 -1 -1 17964 -1 195073 -1 195073 -1 201058 -1 -1 177103 269817 -1 71754 219008 -1 248865 -1 27020 147070 -1 86719 224959 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 80636 -1 -1 -1 -1 281910 180088 17964 123018 201058 -1 -1 86719 -1 2398...
result:
ok ok
Test #9:
score: 0
Accepted
time: 238ms
memory: 6996kb
input:
299999 300000 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 4583175 458317...
output:
158339 158339 5832 38624 89629 11811 71398 59564 164479 44602 254981 158339 71398 197572 158339 158339 44602 158339 20674 80638 71398 14830 158339 158339 158339 158339 158339 71398 158339 288007 71398 -1 44602 158339 264004 71398 158339 224648 95610 116432 161432 158339 44602 98518 161432 89629 1583...
result:
ok ok
Test #10:
score: 0
Accepted
time: 237ms
memory: 6300kb
input:
300000 300000 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806 788806...
output:
20978 167793 92835 56877 167793 258008 20978 156030 203749 173786 47858 92835 138187 167793 167793 167793 92835 167793 258008 138187 167793 126151 167793 29893 167793 92835 44865 104896 167793 92835 203749 185730 80922 167793 248950 44865 185730 167793 44865 288039 -1 47858 138187 -1 44865 288039 10...
result:
ok ok
Test #11:
score: 0
Accepted
time: 135ms
memory: 6236kb
input:
299999 300000 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355592 963355...
output:
299998 -1 -1 -1 299998 299998 -1 -1 299998 299998 299998 -1 299998 299998 299998 299998 299998 299998 -1 -1 299998 299998 -1 -1 299998 299998 299998 299998 -1 299998 -1 -1 -1 -1 -1 299998 -1 -1 -1 -1 299998 -1 299998 -1 299998 299998 299998 299998 -1 -1 299998 -1 -1 299998 299998 299998 299998 -1 29...
result:
ok ok
Test #12:
score: 0
Accepted
time: 138ms
memory: 4976kb
input:
300000 300000 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122736 231122...
output:
299999 -1 299999 299999 -1 -1 -1 299999 -1 299999 299999 299999 299999 299999 299999 299999 299999 299999 -1 -1 299999 -1 -1 299999 -1 299999 299999 299999 299999 299999 299999 -1 -1 299999 299999 -1 -1 299999 299999 -1 -1 299999 299999 299999 -1 299999 -1 -1 299999 299999 -1 -1 -1 299999 -1 299999 ...
result:
ok ok
Test #13:
score: 0
Accepted
time: 143ms
memory: 6700kb
input:
300000 300000 2 1 3 5 0 3 3 2 2 4 1 4 1 4 0 0 1 3 0 1 2 5 1 5 1 5 1 3 0 1 0 2 5 1 1 3 1 3 0 2 5 5 5 0 5 4 5 5 5 2 0 5 0 4 3 0 2 5 3 1 4 1 4 1 1 2 3 4 3 5 0 0 4 2 0 1 5 1 0 1 5 0 3 5 4 0 0 4 1 4 4 1 4 2 3 1 2 5 5 2 0 2 5 1 2 2 5 0 4 1 5 4 0 1 3 3 3 4 1 2 3 1 4 4 2 3 0 1 3 3 1 3 3 4 5 1 4 3 1 3 1 4 0 ...
output:
299984 -1 -1 299965 -1 -1 299871 299965 299965 299965 299979 299965 299979 299965 299965 299965 -1 299871 299871 299985 299965 299979 -1 299965 -1 299979 299984 -1 -1 299985 -1 299965 -1 299965 299979 -1 299965 -1 299979 -1 299965 -1 299965 -1 -1 299985 -1 -1 299979 299965 -1 -1 299965 299979 299871...
result:
ok ok
Test #14:
score: 0
Accepted
time: 135ms
memory: 4924kb
input:
300000 300000 3 3 5 4 1 5 4 4 4 5 4 5 1 4 5 3 2 3 3 4 2 2 1 5 1 4 2 1 5 3 1 1 2 2 3 1 5 5 4 5 4 3 3 1 4 5 2 3 2 4 5 1 4 4 4 4 2 1 5 1 3 4 1 5 4 4 5 4 5 3 2 4 1 5 3 3 5 1 3 1 2 4 2 3 2 2 5 4 5 4 4 1 3 1 3 1 5 1 5 5 3 5 3 5 3 3 4 5 1 5 5 3 5 5 3 4 4 2 2 3 2 2 1 2 2 3 1 4 3 1 4 3 4 2 4 2 4 2 3 4 3 5 2 ...
output:
-1 299988 299997 -1 299999 299988 -1 -1 -1 -1 299988 299988 -1 -1 -1 299965 299999 299965 -1 299997 -1 299965 299999 -1 -1 -1 299997 299999 299965 299965 -1 299996 299999 -1 299988 299988 299997 -1 299996 299999 299988 -1 -1 -1 299999 299999 -1 -1 -1 299965 -1 -1 299999 299965 -1 -1 299965 299988 29...
result:
ok ok
Test #15:
score: 0
Accepted
time: 144ms
memory: 4932kb
input:
300000 300000 0 2 0 2 5 2 0 3 4 3 3 0 1 2 0 0 5 1 1 1 1 1 4 1 0 4 0 2 5 4 2 2 5 4 0 4 2 5 4 3 0 0 0 5 5 3 1 3 1 0 4 0 1 2 0 1 0 4 0 1 3 0 5 3 3 0 1 5 5 2 5 0 2 0 4 5 1 3 5 5 1 2 3 5 2 0 3 3 4 4 4 0 0 2 4 2 2 3 2 1 0 3 3 2 1 3 3 3 1 4 2 5 2 4 1 2 4 2 3 4 1 2 3 3 4 4 3 1 3 5 3 3 2 3 5 4 4 4 0 0 1 0 1 ...
output:
299986 299994 299985 299993 299983 299986 299994 299993 299985 299986 299985 299953 299993 299983 299993 299985 299983 299994 299993 299985 299986 299986 299983 299953 299986 299983 299985 299986 299985 299994 299993 299983 299985 299994 299983 299994 299983 299983 299993 299986 299993 299994 299983...
result:
ok ok
Test #16:
score: 0
Accepted
time: 141ms
memory: 5956kb
input:
300000 300000 3 4 4 1 1 5 1 4 4 1 2 5 4 1 1 1 4 3 5 2 4 5 4 4 4 2 4 2 5 5 5 4 5 4 1 5 2 2 2 5 5 2 1 3 1 2 4 4 1 5 1 3 1 5 3 3 3 4 5 2 5 5 2 4 1 3 2 2 2 5 4 1 3 4 5 4 1 2 3 2 1 1 3 2 4 4 1 4 1 4 3 2 1 3 2 5 1 4 5 4 3 2 2 4 3 1 3 2 4 3 4 3 5 4 3 5 5 2 1 1 3 4 2 2 1 2 1 5 5 2 3 5 2 5 3 5 4 4 5 5 5 2 3 ...
output:
299987 299987 299993 299992 -1 299987 299987 299992 299987 -1 299993 299987 299992 299993 299990 299988 299988 299987 299988 299992 -1 -1 299987 299992 299988 299992 299988 299988 299987 299990 299987 299992 299990 -1 -1 299988 299987 299990 299990 -1 299992 299987 299993 299993 -1 299990 299990 299...
result:
ok ok
Test #17:
score: 0
Accepted
time: 141ms
memory: 4988kb
input:
300000 300000 5 2 3 3 1 5 0 3 2 4 2 5 1 2 4 1 1 5 4 5 0 4 0 4 4 0 0 1 2 3 0 1 1 4 1 1 2 5 3 0 2 4 4 0 2 1 5 0 2 1 0 4 5 4 4 3 5 2 1 0 3 2 1 4 1 2 2 2 4 3 0 3 3 3 0 4 2 0 5 1 5 2 2 0 4 2 2 0 3 0 5 2 3 2 5 3 5 5 1 2 4 2 0 1 2 5 3 4 5 0 0 5 2 3 2 2 5 1 1 3 1 5 4 2 3 3 5 4 0 3 1 2 1 1 5 4 5 2 2 4 4 2 5 ...
output:
299994 -1 299993 299862 -1 -1 299862 -1 299993 299936 299862 -1 299936 299936 299972 299862 -1 299994 -1 299737 -1 -1 299972 299737 -1 299972 299994 -1 299993 -1 -1 299737 -1 299993 299936 -1 -1 299994 299936 299862 299994 299936 299862 -1 -1 299862 299972 299862 299737 299737 299972 299862 299862 2...
result:
ok ok
Test #18:
score: 0
Accepted
time: 141ms
memory: 5916kb
input:
300000 300000 4 1 3 3 1 4 2 1 3 1 1 4 4 5 2 2 2 1 5 2 2 4 3 4 4 4 2 2 1 3 2 5 5 2 3 4 4 4 5 5 3 4 5 2 1 4 4 1 4 5 5 5 3 4 4 4 4 3 4 2 2 4 5 3 5 3 1 5 2 4 1 1 4 4 3 1 5 1 4 2 5 3 3 1 1 3 1 5 5 2 1 1 4 3 4 2 4 5 1 4 4 5 5 5 1 2 3 1 3 4 1 5 5 3 4 4 2 2 5 2 4 1 3 3 3 3 1 3 1 5 4 4 2 2 5 3 2 2 3 1 3 4 1 ...
output:
299981 299998 -1 299998 -1 299923 299981 -1 299993 -1 299998 -1 -1 -1 299991 -1 -1 -1 299923 -1 -1 -1 299923 -1 -1 -1 299981 299923 -1 -1 299998 -1 -1 299993 299993 -1 -1 299991 -1 -1 299998 299923 -1 299991 299991 -1 -1 299981 -1 -1 -1 299981 299991 -1 -1 299991 299998 299981 -1 -1 -1 -1 299998 -1 ...
result:
ok ok
Test #19:
score: -100
Runtime Error
input:
299999 300000 368364702 522726267 191777284 836785831 580519392 679702855 851224739 286998110 385871146 870875427 45817410 544738809 510710727 165619883 318858025 794120765 630021531 511379876 132579749 299399929 498617931 364772164 347885601 884294669 2578901 576388254 66773472 757552580 738656163 ...