QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202978#866. Display of SpringsisaunoyaWA 1ms5188kbC++232.9kb2023-10-06 14:25:592023-10-06 14:26:01

Judging History

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

  • [2023-10-06 14:26:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5188kb
  • [2023-10-06 14:25:59]
  • 提交

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;
      cout << "! " << query(1, N, 1, x) << 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: 0
Wrong Answer
time: 1ms
memory: 5188kb

input:

3
SECOND
SECOND
FIRST
SECOND
SECOND
QUESTION 2

output:

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

result:

wrong answer Expected integer, but "?" found