QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420299#8719. 后继Scintilla#TL 91ms5744kbC++201.6kb2024-05-24 16:19:302024-05-24 16:19:30

Judging History

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

  • [2024-05-24 16:19:30]
  • 评测
  • 测评结果:TL
  • 用时:91ms
  • 内存:5744kb
  • [2024-05-24 16:19:30]
  • 提交

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, o[N], a[N], id[N];

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 >> o[i], id[i] = i;
  while (tc--) {
    int x = 0;
    rep(d, 0, L - 1) {
      // pv(d);
      rep(i, 1, n) a[i] = o[i] ^ x;
      sort(id + 1, id + n + 1, [&](int i, int j) {
        return a[i] < a[j];
      });
      rep(i, 1, n - 1) {
        if (((a[id[i + 1]] ^ a[id[i]]) >> d) != 1) continue;
        if (ask(id[i]) != id[i + 1]) x |= 1 << d;
        break;
      }
    }
    answer(x);
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

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

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5720kb

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: 91ms
memory: 5744kb

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: -100
Time Limit Exceeded

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: