QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420332#8719. 后继Scintilla#AC ✓317ms67632kbC++202.7kb2024-05-24 16:36:192024-05-24 16:36:25

Judging History

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

  • [2024-05-24 16:36:25]
  • 评测
  • 测评结果:AC
  • 用时:317ms
  • 内存:67632kb
  • [2024-05-24 16:36:19]
  • 提交

answer

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <vector>
#include <random>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;

#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define per(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << " \n"[_ == r]

const int N = 4e5 + 10;
const int L = 30;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + (c - 48);
  return x * f;
}

int n, tc, a[N], o[N], pre[L];

int tot = 1, son[N * L][2], dat[N * L];

void insert(int x, int k) {
  int u = 1;
  dat[u] = k;
  per(i, L - 1, 0) {
    int &v = son[u][x >> i & 1];
    if (!v) v = ++tot;
    u = v, dat[u] = k;
  }
}

int querymx(int x, int k) {
  // cout << "querymx x, k = " << x << ' ' << k << endl;
  int u = 1;
  per(i, L - 1, k + 1) {
    u = son[u][pre[k] >> i & 1];
    // cout << "i, u = " << i << ' ' << u << endl;
  }
  u = son[u][0];
  assert(u);
  per(i, k - 1, 0) {
    if (dat[son[u][~x >> i & 1]]) {
      u = son[u][~x >> i & 1];
    }
    else u = son[u][x >> i & 1];
  }
  return dat[u];
}

int querymn(int x, int k) {
  int u = 1;
  per(i, L - 1, k + 1) {
    u = son[u][pre[k] >> i & 1];
  }
  u = son[u][1];
  assert(u);
  per(i, k - 1, 0) {
    if (dat[son[u][x >> i & 1]]) {
      u = son[u][x >> i & 1];
    }
    else u = son[u][~x >> i & 1];
  }
  return dat[u];
}

int ask(int i) {
  cout << "? " << i << endl;
  cout.flush();
  int res;
  cin >> res;
  return res;
}

void answer(int x) {
  cout << "! " << x << endl;
  cout.flush();
  return;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n >> tc;
  rep(i, 1, n) cin >> a[i], o[i] = i;
  rep(i, 1, n) insert(a[i], i);
  sort(o + 1, o + n + 1, [&](int i, int j) {
    return a[i] < a[j];
  });
  rep(d, 0, L - 1) {
    pre[d] = -1;
    rep(i, 1, n - 1) {
      if (((a[o[i + 1]] ^ a[o[i]]) >> d) == 1) {
        // cout << "d, i = " << d << ' ' << i << endl;
        pre[d] = (a[o[i]] >> d) << d;
        break;
      }
    }
  }
  // pa(pre, 0, L - 1);
  while (tc--) {
    int x = 0;
    rep(d, 0, L - 1) {
      if (!~pre[d]) continue;
      int p = querymx(x, d);
      int q = querymn(x, d);
      if (ask(p) != q) x |= 1 << d;
    }
    answer(x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5628kb

input:

5 1
1 2 3 4 5
1
5
5

output:

? 2
? 1
? 1
! 3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7820kb

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 2ms
memory: 7748kb

input:

10 10
380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199
3
4
-1
1
7
-1
3
4
10
7
-1
-1
7
10
7
1
-1
-1
7
-1
7
2
3
-1
3
4
10
-1
2
2
3
4
10
-1
2
2
3
7
6
4
-1
-1
7
-1
7
2
3
-1
6
7
6
8
3
-1
3
7
8
9
6
8

output:

? 4
? 6
? 3
? 5
? 10
? 3
! 271581184
? 4
? 6
? 3
? 5
? 10
? 10
! 296747008
? 4
? 6
? 4
? 5
? 10
? 10
! 286523392
? 4
? 6
? 4
? 5
? 10
? 6
! 278134784
? 4
? 6
? 3
? 5
? 10
? 10
! 28311552
? 4
? 6
? 3
? 5
? 10
? 10
! 28311552
? 4
? 6
? 3
? 5
? 10
? 10
! 293601280
? 4
? 6
? 4
? 5
? 10
? 6
! 278134784
?...

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 35ms
memory: 7836kb

input:

100 3000
416322873 449728250 688705913 946343465 16202884 153238658 573284215 724198910 577719053 868106680 951494055 942341618 190594266 331719623 856324110 977865755 151782935 163752541 1565918 870244322 299691610 37854919 198293342 152446496 549402023 869857831 869628458 573984494 162791133 94423...

output:

? 11
? 85
? 88
? 15
? 49
? 22
? 19
? 19
? 19
? 19
? 19
? 19
? 41
! 184027136
? 11
? 85
? 88
? 15
? 49
? 22
? 19
? 61
? 55
? 55
? 55
? 55
? 55
! 445644800
? 11
? 85
? 88
? 15
? 49
? 22
? 19
? 19
? 77
? 77
? 57
? 57
? 70
! 145555456
? 11
? 85
? 88
? 15
? 49
? 22
? 19
? 19
? 77
? 77
? 77
? 77
? 41
! 17...

result:

ok 3000 numbers

Test #5:

score: 0
Accepted
time: 317ms
memory: 67632kb

input:

400000 3000
406697044 910508999 785308673 89872855 911511537 786066190 569035255 791369083 231783630 373589094 1005702647 785128281 910883228 612232307 428493618 691767283 288087749 380834477 1012471581 807583302 951439706 172399529 651163374 395700503 212381194 528978756 628513589 230244101 1046447...

output:

? 208131
? 190730
? 201285
? 65179
? 109637
? 150514
? 69846
? 198186
? 274803
? 374076
? 110252
? 196742
? 358945
? 358945
? 358945
? 358945
? 358945
? 393313
? 393313
? 348261
? 193410
? 77860
? 77860
? 77860
? 230877
? 371824
? 55602
? 304394
? 304394
? 248810
! 140702791
? 208131
? 190730
? 2012...

result:

ok 3000 numbers

Test #6:

score: 0
Accepted
time: 280ms
memory: 39688kb

input:

400000 3000
49852143 106643027 78538081 13535110 34673790 361240760 358287062 285333122 15578697 106130051 320170693 107023555 72813915 2799162 286900401 787319 332890808 75095435 110215229 74827421 107485420 300695656 71750101 285593446 37660664 397030779 392989831 16018850 14036294 361777963 11269...

output:

? 367047
? 263139
? 367047
? 367047
? 94916
? 94916
? 40340
? 214138
? 358798
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
? 38445
! 113099425
? 367047
? 263139
? 90385
? 263139
? 263139
? 162978
? 162978
? 162978
? 107911
? 107911
? 107911
? 107911
? 107911
? 1079...

result:

ok 3000 numbers

Extra Test:

score: 0
Extra Test Passed