QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#787893#9669. Function QueryTJ_Andeviking#AC ✓525ms77740kbC++202.4kb2024-11-27 15:09:082024-11-27 16:16:30

Judging History

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

  • [2024-11-27 16:16:30]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:525ms
  • 内存:77740kb
  • [2024-11-27 16:16:04]
  • hack成功,自动添加数据
  • (/hack/1261)
  • [2024-11-27 15:09:08]
  • 评测
  • 测评结果:100
  • 用时:494ms
  • 内存:77908kb
  • [2024-11-27 15:09:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
#define range(x) (x).begin(), (x).end()

int tr[10000005][2];
int mx[10000005][2];
int tot = 1;
constexpr int limit = 1 << 29;
void insert(int x, int pos)
{
    int now = 1;
    for (int i = limit; i; i >>= 1) {
        int tag = bool(x & i);
        mx[now][tag] = max(mx[now][tag], pos);
        if (!tr[now][tag])
            tr[now][tag] = ++tot;
        now = tr[now][tag];
    }
}

int ck;
int ask_le(int x)
{
    int now = 1;
    int ans = 0;
    for (int i = limit; i; i >>= 1) {
        int tag = bool(x & i);
        int tck = bool(ck & i);

        if (tag != tck)
            ans = max(ans, mx[now][tck]);
        now = tr[now][tag];
        if (!now)
            return ans;
    }
    return ans;
}

int ask_ge(int x)
{
    int now = 1;
    int ans = 0;
    for (int i = limit; i; i >>= 1) {
        int tag = bool(x & i);
        int tck = bool(ck & i);

        if (tag == tck)
            ans = max(ans, mx[now][tck ^ 1]);
        now = tr[now][tag];
        if (!now)
            return ans;
    }
    return ans;
}
void solve()
{
    int n, q;
    cin >> n >> q;

    map<int, int> mp;
    // vector<int> aa(1);
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        insert(x, i);
        mp[x] = i;
        // aa.push_back(x);
    }

    while (q--) {
        int a, b;
        cin >> a >> b;

        int y = (a ^ b);
        ck = a;
        int ans = 0;
        if (mp.count(y)) {
            int pos = mp[y];
            if (pos == n)
                ans = n - 1;
            else
                ans = pos;
        }
        else {
            // cout << ask_le(y) << ' ' << ask_ge(y) << '\n';
            int pos = min(ask_le(y), ask_ge(y));
            if (!pos)
                ans = -1;
            else
                ans = pos;
        }

        cout << ans << '\n';
        // auto f = [&](int x) {
        //     return (a ^ x) - b;
        // };
        // if (ans != -1) {
        //     if (f(aa[ans]) * f(aa[ans + 1]) > 0)
        //         cout << a << ' ' << b << ' ' << ans << '\n';
        // }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t = 1;

    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: 3552kb

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: 3772kb

input:

2 1
3 3
0 3

output:

1

result:

ok ok

Test #3:

score: 0
Accepted
time: 62ms
memory: 3620kb

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
209610
119478
149700
119478
269763
59791
89695
119478
209610
179614
299999
239765
89695
-1
59791
269763
179614
179614
209610
209610
209610
209610
119478
239765
299999
89695
179614
89695
269763
239765
209610
59791
89695
299999
89695
149700
89695
179614
59791
59791
209610
89695
59791
179614
1796...

result:

ok ok

Test #4:

score: 0
Accepted
time: 61ms
memory: 3560kb

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:

90063
59824
269973
149876
299999
120024
239818
149876
29872
149876
149876
59824
209816
239818
120024
120024
90063
59824
239818
149876
90063
239818
120024
179677
209816
90063
29872
179677
149876
179677
90063
299999
239818
209816
29872
149876
269973
179677
209816
59824
269973
59824
179677
179677
14987...

result:

ok ok

Test #5:

score: 0
Accepted
time: 87ms
memory: 3628kb

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
239680
149833
269781
149833
269781
59912
30018
179888
269781
59912
209643
269781
149833
119893
209643
179888
209643
-1
269781
119893
89929
269781
269781
89929
269781
209643
89929
30018
269781
119893
59912
59912
269781
59912
269781
269781
89929
239680
269781
59912
30018
209643
59912
59912...

result:

ok ok

Test #6:

score: 0
Accepted
time: 82ms
memory: 3620kb

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:

179553
239884
269967
59597
209808
269967
269967
59597
209808
59597
59597
269967
269967
179553
239884
239884
89750
89750
149501
59597
179553
269967
269967
269967
269967
269967
209808
269967
59597
269967
269967
89750
59597
269967
179553
119571
269967
149501
59597
89750
269967
29668
269967
149501
59597...

result:

ok ok

Test #7:

score: 0
Accepted
time: 94ms
memory: 3860kb

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
138222
-1
227979
290975
114235
-1
233864
153067
-1
-1
114235
153067
269855
-1
233864
-1
59939
-1
-1
153067
62885
153067
293964
192250
-1
171094
-1
-1
11995
-1
-1
62885
-1
153067
153067
-1
62885
222078
269855
290975
-1
153067
-1
-1
114235
-1
50934
-1
263829
-1
114235
62885
-1
-1
62885
-1
25791...

result:

ok ok

Test #8:

score: 0
Accepted
time: 68ms
memory: 3860kb

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
135013
-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
227993
-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: 110ms
memory: 3656kb

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:

254981
288007
71398
158339
89629
44602
86633
158339
254981
158339
293992
254981
158339
254981
254981
270073
158339
254981
158339
158339
125297
17700
251913
254981
254981
293992
254981
125297
158339
293992
89629
-1
71398
254981
288007
158339
270073
254981
104451
125297
254981
254981
158339
158339
197...

result:

ok ok

Test #10:

score: 0
Accepted
time: 114ms
memory: 3860kb

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
293997
167793
56877
258008
288039
167793
164917
258008
218910
167793
167793
164917
264063
258008
264063
167793
288039
258008
138187
288039
138187
258008
167793
258008
167793
47858
167793
258008
92835
218910
218910
167793
258008
248950
167793
203749
258008
167793
288039
-1
167793
156030
-1
167...

result:

ok ok

Test #11:

score: 0
Accepted
time: 80ms
memory: 3596kb

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: 81ms
memory: 3564kb

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: 70ms
memory: 3660kb

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
299999
-1
-1
299985
299999
299999
299996
299998
299999
299998
299999
299996
299999
-1
299985
299985
299993
299996
299999
-1
299996
-1
299999
299999
-1
-1
299993
-1
299999
-1
299999
299999
-1
299999
-1
299999
-1
299996
-1
299999
-1
-1
299993
-1
-1
299999
299999
-1
-1
299996
299999
299985...

result:

ok ok

Test #14:

score: 0
Accepted
time: 72ms
memory: 3616kb

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
299996
299998
-1
299999
299996
-1
-1
-1
-1
299996
299996
-1
-1
-1
299999
299998
299999
-1
299998
-1
299999
299998
-1
-1
-1
299998
299999
299999
299999
-1
299996
299999
-1
299996
299996
299998
-1
299996
299999
299988
-1
-1
-1
299999
299999
-1
-1
-1
299999
-1
-1
299999
299999
-1
-1
299999
299988
29...

result:

ok ok

Test #15:

score: 0
Accepted
time: 58ms
memory: 3592kb

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:

299994
299995
299998
299999
299999
299994
299995
299999
299998
299994
299998
299992
299999
299999
299999
299998
299999
299995
299999
299998
299994
299994
299999
299992
299994
299999
299998
299994
299998
299995
299999
299999
299998
299995
299999
299995
299999
299999
299999
299994
299999
299995
299999...

result:

ok ok

Test #16:

score: 0
Accepted
time: 58ms
memory: 3560kb

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
299998
299999
299999
299996
299999
299993
-1
-1
299996
299993
299999
299993
299999
299999
299996
299998
299996
299993
299998
-1
-1
299999
299996
299998
299998
-1
299993
299996
299999
299999
-1
299998
299998
299...

result:

ok ok

Test #17:

score: 0
Accepted
time: 61ms
memory: 3564kb

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:

299999
-1
299993
299990
-1
-1
299990
-1
299993
299999
299990
-1
299999
299999
299997
299990
-1
299999
-1
299994
-1
-1
299997
299994
-1
299997
299999
-1
299993
-1
-1
299994
-1
299993
299999
-1
-1
299999
299999
299990
299999
299999
299990
-1
-1
299990
299997
299990
299994
299994
299997
299990
299990
2...

result:

ok ok

Test #18:

score: 0
Accepted
time: 65ms
memory: 3572kb

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:

299998
299999
-1
299999
-1
299985
299998
-1
299993
-1
299999
-1
-1
-1
299999
-1
-1
-1
299985
-1
-1
-1
299985
-1
-1
-1
299998
299985
-1
-1
299999
-1
-1
299993
299993
-1
-1
299999
-1
-1
299999
299985
-1
299999
299999
-1
-1
299998
-1
-1
-1
299998
299999
-1
-1
299999
299999
299998
-1
-1
-1
-1
299999
-1
...

result:

ok ok

Test #19:

score: 0
Accepted
time: 525ms
memory: 77676kb

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:

299998
299998
299998
299998
299991
299998
299998
299985
299992
299991
299998
299998
299998
299998
299998
299991
299992
299947
299995
299998
299991
299998
299355
299998
299992
299991
299995
299984
299998
299998
299998
299998
299998
299998
299998
299998
299998
299998
299998
299995
299998
299998
299981...

result:

ok ok

Test #20:

score: 0
Accepted
time: 484ms
memory: 77740kb

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:

299991
299997
299999
299999
299999
299999
299999
299998
299996
299999
299999
299999
299991
299999
299997
299999
299996
299999
299999
299999
299999
299996
299988
299999
299999
299991
299997
299999
299991
299994
299999
299997
299996
299999
299996
299996
299988
299996
299962
299999
299999
299999
299999...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed