QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202982#866. Display of SpringsisaunoyaWA 15ms5192kbC++232.9kb2023-10-06 14:26:362023-10-06 14:26:38

Judging History

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

  • [2023-10-06 14:26:38]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5192kb
  • [2023-10-06 14:26:36]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (int i = 0; i < a; i++)
#define rep2(i, a) for (int i = 0; i < a; i++)
#define rep3(i, a, b) for (int i = a; i < b; i++)
#define rep4(i, a, b, c) for (int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second

int get(int a, int b, int w) {
  if (a == -1) {
    return b;
  }
  if (b == -1) {
    return a;
  }
  cout << "? " << a << " " << b << " " << w << endl;
  string s;
  cin >> s;
  if (s == "FIRST") {
    return a;
  } else {
    return b;
  }
}

const int N = 1e5;
int id[N * 4];
void update(int l, int r, int p, int x) {
  if (id[p] == -1) {
    id[p] = x;
    return;
  }
  if (l == r) {
    if (get(id[p], x, l) == x) {
      id[p] = x;
    }
    return;
  }
  int m = (l + r) / 2;
  int ql = get(id[p], x, l);
  int qr = get(id[p], x, r);
  if (ql == id[p] && qr == id[p]) {
    return;
  }
  if (ql == x && qr == x) {
    id[p] = x;
    return;
  }
  int qm = get(id[p], x, m);
  if (qm == x) {
    int y = id[p];
    id[p] = x;
    if (ql == y)
      update(l, m, p * 2, y);
    if (qr == y)
      update(m + 1, r, p * 2 + 1, y);
    return;
  }
  if (qm == id[p]) {
    if (ql == x) 
      update(l, m, p * 2, x);
    if (qr == x)
      update(m + 1, r, p * 2 + 1, x);
    return;
  }
}
int query(int l, int r, int p, int x) {
  if (l == r) {
    return id[p];
  }
  int m = (l + r) / 2;
  int y;
  if (x <= m)
    y = query(l, m, p * 2, x);
  else
    y = query(m + 1, r, p * 2 + 1, x);
  return get(id[p], y, x);
}

void solve() {
  memset(id, -1, sizeof id);
  int n;
  cin >> n;
  for (int b = 0; b < n; b++) {
    update(1, N, 1, b);
  }
  cout << "!" << endl;
  while (true) {
    string s;
    cin >> s;
    if (s == "QUESTION") {
      int x;
      cin >> x;
      int y = query(1, N, 1, x);
      cout << "! " << y << endl;
    } else {
      return;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
SECOND
SECOND
FIRST
SECOND
SECOND
QUESTION 2
SECOND
QUESTION 6
FIRST
FINISH

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 1 2 50000
!
? 2 1 2
! 1
? 2 1 6
! 2

result:

ok Correct answer

Test #2:

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

input:

6
EQUAL
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
QUESTION 1
SECOND
SECOND
SECOND
SECOND
QUESTION 2
EQUAL
SECOND
SECOND
SECOND
QUESTION...

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 1 2 50000
? 2 3 1
? 2 3 100000
? 2 3 50000
? 1 2 1
? 1 2 50000
? 1 2 25000
? 3 4 1
? 3 4 100000
? 3 4 50000
? 2 3 1
? 2 3 50000
? 2 3 25000
? 1 2 1
? 1 2 25000
? 1 2 12500
? 4 5 1
? 4 5 100000
? 4 5 50000
? 3 4 1
? 3 4 50000
? 3 4 25000
? 2 3 1
? 2 3 25000...

result:

ok Correct answer

Test #3:

score: 0
Accepted
time: 3ms
memory: 5192kb

input:

326
FIRST
FIRST
SECOND
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
SECOND
FIRST
FIRST
SECOND
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
SECOND
FIRST
FIRST
FIRST
FIRST
SECOND
FIRST
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
SECOND
FIRST
FIRST
SECOND
SECOND
FIRS...

output:

? 0 1 1
? 0 1 100000
? 0 2 1
? 0 2 100000
? 0 2 50000
? 0 3 1
? 0 3 100000
? 0 3 50000
? 2 0 1
? 2 0 50000
? 2 0 25000
? 3 4 1
? 3 4 100000
? 3 4 50000
? 0 4 1
? 0 4 50000
? 0 4 25000
? 2 4 1
? 2 4 25000
? 3 5 1
? 3 5 100000
? 3 6 1
? 3 6 100000
? 3 6 50000
? 0 6 1
? 0 6 50000
? 3 7 1
? 3 7 100000
?...

result:

ok Correct answer

Test #4:

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

input:

19
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
SECOND
SECOND
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
QUESTION 87421
QUESTION 49361
FIRST
QUESTION 69685
QUESTION 92972...

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 1 3 1
? 1 3 100000
? 1 4 1
? 1 4 100000
? 1 5 1
? 1 5 100000
? 1 6 1
? 1 6 100000
? 1 6 50000
? 6 7 1
? 6 7 100000
? 6 8 1
? 6 8 100000
? 8 9 1
? 8 9 100000
? 9 10 1
? 9 10 100000
? 9 11 1
? 9 11 100000
? 9 12 1
? 9 12 100000
? 12 13 1
? 12 13 100000
? 12 ...

result:

ok Correct answer

Test #5:

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

input:

500
SECOND
SECOND
SECOND
SECOND
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
...

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 2 3 1
? 2 3 100000
? 3 4 1
? 3 4 100000
? 3 5 1
? 3 5 100000
? 3 6 1
? 3 6 100000
? 3 7 1
? 3 7 100000
? 7 8 1
? 7 8 100000
? 7 9 1
? 7 9 100000
? 7 10 1
? 7 10 100000
? 7 11 1
? 7 11 100000
? 7 12 1
? 7 12 100000
? 7 13 1
? 7 13 100000
? 7 14 1
? 7 14 100...

result:

ok Correct answer

Test #6:

score: 0
Accepted
time: 9ms
memory: 5188kb

input:

500
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQUAL
EQ...

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 2 3 1
? 2 3 100000
? 3 4 1
? 3 4 100000
? 4 5 1
? 4 5 100000
? 5 6 1
? 5 6 100000
? 6 7 1
? 6 7 100000
? 7 8 1
? 7 8 100000
? 8 9 1
? 8 9 100000
? 9 10 1
? 9 10 100000
? 10 11 1
? 10 11 100000
? 11 12 1
? 11 12 100000
? 12 13 1
? 12 13 100000
? 13 14 1
? 1...

result:

ok Correct answer

Test #7:

score: 0
Accepted
time: 4ms
memory: 5192kb

input:

500
SECOND
SECOND
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
SE...

output:

? 0 1 1
? 0 1 100000
? 1 2 1
? 1 2 100000
? 1 3 1
? 1 3 100000
? 3 4 1
? 3 4 100000
? 3 5 1
? 3 5 100000
? 3 6 1
? 3 6 100000
? 3 7 1
? 3 7 100000
? 3 8 1
? 3 8 100000
? 3 9 1
? 3 9 100000
? 3 10 1
? 3 10 100000
? 3 11 1
? 3 11 100000
? 3 12 1
? 3 12 100000
? 3 13 1
? 3 13 100000
? 13 14 1
? 13 14 1...

result:

ok Correct answer

Test #8:

score: 0
Accepted
time: 15ms
memory: 5084kb

input:

500
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FI...

output:

? 0 1 1
? 0 1 100000
? 0 2 1
? 0 2 100000
? 0 3 1
? 0 3 100000
? 0 4 1
? 0 4 100000
? 0 5 1
? 0 5 100000
? 0 6 1
? 0 6 100000
? 0 7 1
? 0 7 100000
? 0 8 1
? 0 8 100000
? 0 9 1
? 0 9 100000
? 0 10 1
? 0 10 100000
? 0 11 1
? 0 11 100000
? 0 12 1
? 0 12 100000
? 0 13 1
? 0 13 100000
? 0 14 1
? 0 14 100...

result:

ok Correct answer

Test #9:

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

input:

2
FIRST
SECOND
SECOND
QUESTION 64500
QUESTION 22602
FIRST
QUESTION 37446
FIRST
QUESTION 97972
QUESTION 78630
QUESTION 75591
QUESTION 63328
QUESTION 64746
QUESTION 94532
QUESTION 51275
QUESTION 12189
FIRST
QUESTION 64341
QUESTION 85825
QUESTION 63713
QUESTION 36778
FIRST
QUESTION 27116
FIRST
QUESTION...

output:

? 0 1 1
? 0 1 100000
? 0 1 50000
!
! 1
? 1 0 22602
! 1
? 1 0 37446
! 1
! 1
! 1
! 1
! 1
! 1
! 1
! 1
? 1 0 12189
! 1
! 1
! 1
! 1
? 1 0 36778
! 1
? 1 0 27116
! 1
? 1 0 18630
! 1
! 1
? 1 0 28074
! 1
! 1
! 1
? 1 0 39195
! 1
! 1
? 1 0 1182
! 1
! 1
! 1
! 1
? 1 0 7017
! 1
? 1 0 13589
! 1
! 1
! 1
? 1 0 48324...

result:

ok Correct answer

Test #10:

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

input:

2
FIRST
SECOND
SECOND
QUESTION 54311
QUESTION 8466
SECOND
QUESTION 82055
QUESTION 65419
QUESTION 5271
SECOND
QUESTION 4799
SECOND
QUESTION 21521
FIRST
QUESTION 66767
QUESTION 24897
FIRST
QUESTION 69127
QUESTION 84527
QUESTION 23303
FIRST
QUESTION 88924
QUESTION 56421
QUESTION 88108
QUESTION 74033
QU...

output:

? 0 1 1
? 0 1 100000
? 0 1 50000
!
! 1
? 1 0 8466
! 0
! 1
! 1
? 1 0 5271
! 0
? 1 0 4799
! 0
? 1 0 21521
! 1
! 1
? 1 0 24897
! 1
! 1
! 1
? 1 0 23303
! 1
! 1
! 1
! 1
! 1
? 1 0 25348
! 1
? 1 0 10105
! 0
! 1
? 1 0 33359
! 1
? 1 0 49782
! 1
? 1 0 20392
! 1
! 1
! 1
? 1 0 4246
! 0
! 1
? 1 0 8620
! 0
? 1 0 ...

result:

ok Correct answer

Test #11:

score: -100
Wrong Answer
time: 13ms
memory: 5168kb

input:

500
SECOND
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
SECOND
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
SECOND
FIRST
FIRST
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND
FIRST
SECOND
SECOND...

output:

? 0 1 1
? 0 1 100000
? 0 1 50000
? 0 2 1
? 0 2 100000
? 0 2 50000
? 1 0 1
? 1 0 50000
? 1 0 25000
? 2 3 1
? 2 3 100000
? 2 3 50000
? 0 3 1
? 0 3 50000
? 0 3 25000
? 1 0 1
? 1 0 25000
? 1 0 12500
? 2 4 1
? 2 4 100000
? 2 4 50000
? 3 2 1
? 3 2 50000
? 3 2 25000
? 0 3 1
? 0 3 25000
? 0 3 12500
? 1 0 1
...

result:

wrong answer Invalid input: Too many queries