QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#923369 | #9669. Function Query | woodie_0064# | AC ✓ | 293ms | 50896kb | C++20 | 2.1kb | 2025-03-01 20:33:35 | 2025-03-01 20:33:39 |
Judging History
answer
#include <bits/stdc++.h>
#define bit(x) (1LL << (x))
#define lowbit(x) (x & (-x))
#define SQU(x) ((x) * (x))
#define ls id << 1
#define rs id << 1 | 1
//#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e5 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int inv2 = (mod + 1) / 2;
ll qpow(ll x,ll y) {
ll res = 1;
while(y) {
if(y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
void add(int &x,int y) {
x += y;
if(x >= mod) x -= mod;
}
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int ch[maxn * 30][2],p[maxn * 30],tot;
void insert(int x,int y) {
int u = 0;
for(int i = 29;i >= 0;i--) {
int nxt = ((x >> i) & 1);
if(!ch[u][nxt]) ch[u][nxt] = ++tot;
u = ch[u][nxt];
}
p[u] = y;
}
pair <int,int> query(int x) {
int mxu = 0,mnu = 0;
for(int i = 29;i >= 0;i--) {
int nxt = ((x >> i) & 1);
if(ch[mnu][nxt]) mnu = ch[mnu][nxt];
else mnu = ch[mnu][nxt ^ 1];
if(ch[mxu][nxt ^ 1]) mxu = ch[mxu][nxt ^ 1];
else mxu = ch[mxu][nxt];
}
return make_pair(min(p[mxu],p[mnu]),max(p[mxu],p[mnu]));
}
void solve() {
int n,q;cin >> n >> q;
vector <int> a(n + 1);
for(int i = 1;i <= n;i++) {
cin >> a[i];
insert(a[i],i);
}
while(q--) {
int x,y;cin >> x >> y;
auto [l,r] = query(x);
if(l == r) {
if((x ^ a[1]) == y) cout << "1\n";
else cout << "-1\n";
continue;
}
if(1LL * ((x ^ a[l]) - y) * ((x ^ a[r]) - y) > 0) {
cout << "-1\n";
continue;
}
int L = (x ^ a[l]) - y;
r -= 1;
while(l < r) {
int mid = (l + r + 1) >> 1;
if(1LL * L * ((a[mid] ^ x) - y) > 0) l = mid;
else r = mid - 1;
}
cout << l << '\n';
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
return 0;
}
/*
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
5 6 3 5 1 2 4 0 2 1 1 2 3 3 2 4 2 5 8
output:
2 3 2 1 4 -1
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 1 3 3 0 3
output:
1
result:
ok ok
Test #3:
score: 0
Accepted
time: 85ms
memory: 4608kb
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:
209610 209610 119478 119478 149700 269763 89695 59791 209610 209610 149700 209610 269763 59791 -1 89695 209610 209610 209610 179614 89695 149700 209610 209610 209610 269763 89695 149700 209610 209610 209610 209610 29721 89695 209610 89695 89695 89695 209610 29721 89695 209610 89695 89695 149700 1497...
result:
ok ok
Test #4:
score: 0
Accepted
time: 86ms
memory: 4608kb
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 29872 120024 120024 29872 179677 209816 90063 90063 59824 29872 209816 120024 59824 209816 120024 149876 179677 59824 29872 149876 120024 149876 59824 269973 209816 179677 29872 120024 239818 149876 179677 29872 239818 29872 149876 149876 120024 ...
result:
ok ok
Test #5:
score: 0
Accepted
time: 98ms
memory: 4480kb
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 89929 59912 269781 269781 119893 59912 59912 59912 269781 269781 59912 59912 209643 269781 269781 209643 59912 269781 -1 269781 269781 149833 269781 269781 269781 269781 269781 149833 59912 269781 119893 59912 59912 269781 59912 269781 209643 149833 59912 59912 269781 269781 269781 269781 5991...
result:
ok ok
Test #6:
score: 0
Accepted
time: 98ms
memory: 4608kb
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 269967 59597 149501 269967 269967 59597 179553 59597 269967 269967 269967 209808 149501 209808 59597 149501 119571 59597 59597 269967 269967 269967 269967 209808 269967 269967 59597 59597 269967 149501 59597 269967 209808 149501 269967 59597 59597 59597 269967 269967 209808 269967 2699...
result:
ok ok
Test #7:
score: 0
Accepted
time: 102ms
memory: 4608kb
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:
153067 153067 -1 153067 153067 114235 -1 233864 153067 -1 -1 114235 153067 153067 -1 153067 -1 59939 -1 -1 153067 62885 153067 153067 153067 -1 192250 -1 -1 11995 -1 -1 62885 -1 153067 153067 -1 62885 210256 233864 290975 -1 126309 -1 -1 114235 -1 50934 -1 153067 -1 114235 39023 -1 -1 62885 -1 25791...
result:
ok ok
Test #8:
score: 0
Accepted
time: 82ms
memory: 4608kb
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: 174ms
memory: 4480kb
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 71398 158339 89629 44602 71398 158339 164479 158339 254981 188541 158339 197572 158339 158339 158339 158339 158339 158339 125297 17700 158339 197572 158339 158339 158339 125297 158339 288007 71398 -1 71398 158339 264004 158339 158339 254981 95610 125297 161432 158339 158339 98518 19757...
result:
ok ok
Test #10:
score: 0
Accepted
time: 170ms
memory: 4480kb
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:
167793 167793 167793 56877 167793 258008 167793 164917 258008 218910 167793 167793 156030 167793 167793 167793 167793 167793 258008 138187 167793 138187 167793 167793 194783 167793 47858 104896 167793 92835 203749 185730 167793 167793 248950 167793 203749 185730 167793 288039 -1 167793 156030 -1 167...
result:
ok ok
Test #11:
score: 0
Accepted
time: 94ms
memory: 4608kb
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:
1 -1 -1 -1 1 1 -1 -1 1 1 1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 1 1 1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 1 -1 -1 1 -1 -1 1 1 1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 1 1 1 1 -1 -1 -1 1 -1 1 1 1 1 1 -1 1 1 1 1 1 1 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 1 1 1 1 -1 -1 1 -1 1 1 -1 1 -1 1 1 1 1 1 1 1 1 -1 -1 1 1...
result:
ok ok
Test #12:
score: 0
Accepted
time: 93ms
memory: 4480kb
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:
1 -1 1 1 -1 -1 -1 1 -1 1 1 1 1 1 1 1 1 1 -1 -1 1 -1 -1 1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 -1 1 1 -1 -1 1 1 1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 -1 1 1 -1 1 -1 1 -1 1 1 -1 1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 1 1 -1 1 -1 1 1 -1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 1 1 -1 1 1 1 1 1 1 1 -1 1 1 1 -1 1 1 1 1 -1 -1 -1 1 -1 -1 -1...
result:
ok ok
Test #13:
score: 0
Accepted
time: 74ms
memory: 4608kb
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:
299999 -1 -1 299993 -1 -1 299996 299999 299996 299993 299999 299996 299999 299999 299993 299999 -1 299996 299999 299996 299993 299993 -1 299993 -1 299999 299994 -1 -1 299999 -1 299996 -1 299996 299999 -1 299996 -1 299993 -1 299999 -1 299993 -1 -1 299985 -1 -1 299999 299996 -1 -1 299999 299999 299996...
result:
ok ok
Test #14:
score: 0
Accepted
time: 76ms
memory: 4608kb
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 299994 299991 -1 -1 -1 -1 299996 299996 -1 -1 -1 299991 299994 299999 -1 299997 -1 299999 299997 -1 -1 -1 299997 299998 299999 299991 -1 299996 299998 -1 299991 299991 299996 -1 299996 299994 299996 -1 -1 -1 299998 299998 -1 -1 -1 299999 -1 -1 299994 299991 -1 -1 299996 299988 29...
result:
ok ok
Test #15:
score: 0
Accepted
time: 76ms
memory: 4608kb
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:
299993 299994 299998 299999 299998 299993 299994 299999 299998 299993 299998 299992 299999 299998 299999 299998 299998 299994 299999 299998 299993 299993 299998 299992 299993 299998 299998 299993 299998 299994 299999 299998 299998 299994 299998 299994 299998 299998 299999 299993 299999 299994 299998...
result:
ok ok
Test #16:
score: 0
Accepted
time: 74ms
memory: 4480kb
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:
299996 299996 299999 299993 -1 299996 299996 299993 299996 -1 299999 299996 299993 299999 299997 299999 299999 299996 299999 299993 -1 -1 299996 299993 299999 299993 299999 299999 299996 299997 299996 299993 299997 -1 -1 299999 299996 299997 299997 -1 299993 299996 299999 299999 -1 299997 299997 299...
result:
ok ok
Test #17:
score: 0
Accepted
time: 73ms
memory: 4608kb
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:
299991 -1 299991 299990 -1 -1 299990 -1 299991 299990 299990 -1 299990 299990 299993 299990 -1 299991 -1 299993 -1 -1 299993 299993 -1 299993 299991 -1 299991 -1 -1 299993 -1 299991 299990 -1 -1 299991 299990 299990 299991 299990 299990 -1 -1 299990 299993 299990 299993 299993 299993 299990 299990 2...
result:
ok ok
Test #18:
score: 0
Accepted
time: 69ms
memory: 4480kb
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:
299995 299993 -1 299993 -1 299993 299995 -1 299993 -1 299993 -1 -1 -1 299993 -1 -1 -1 299993 -1 -1 -1 299993 -1 -1 -1 299995 299993 -1 -1 299993 -1 -1 299993 299993 -1 -1 299993 -1 -1 299993 299993 -1 299993 299993 -1 -1 299995 -1 -1 -1 299995 299993 -1 -1 299993 299993 299995 -1 -1 -1 -1 299993 -1 ...
result:
ok ok
Test #19:
score: 0
Accepted
time: 289ms
memory: 50152kb
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 ...
output:
181694 120167 87803 178683 48011 259191 155869 16498 75950 26156 108241 221839 121724 120269 178466 141265 110181 41331 232061 246326 215883 140363 214598 146714 41699 234182 58151 115781 242277 264063 97016 153747 235501 114587 38679 123572 157589 6930 135025 203681 140306 105866 101549 257386 1175...
result:
ok ok
Test #20:
score: 0
Accepted
time: 293ms
memory: 50896kb
input:
300000 300000 329363808 410837414 386542070 316091908 224988184 590807425 401154024 565635770 86332895 871768724 648980535 429516720 974692004 393242573 258082599 541700334 365570636 140418397 22543471 474596985 928885580 593375594 883649657 723085701 136251090 79716489 444939923 965935970 173809628...
output:
125054 157109 188194 107195 107151 117146 240250 250024 207511 277492 209477 221395 263641 58946 227139 183504 159439 190405 35950 151055 8160 46668 59674 156673 167006 209803 167358 114769 203576 148534 89934 163686 140741 93968 67375 14004 115121 285950 285192 234676 253164 126157 209738 30097 163...
result:
ok ok
Extra Test:
score: 0
Extra Test Passed