QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32618#866. Display of SpringsAutumnKiteTL 1ms3644kbC++171.9kb2022-05-22 13:26:102022-05-22 13:26:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-22 13:26:11]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3644kb
  • [2022-05-22 13:26:10]
  • 提交

answer

#include <bits/stdc++.h>

const int LIM = 100000;

int compare(int i, int j, int x) {
  std::cout << "? " << i << " " << j << " " << x << std::endl;
  std::string tmp;
  std::cin >> tmp;
  if (tmp == "FIRST") {
    return 1;
  } else if (tmp == "SECOND") {
    return -1;
  } else {
    return 0;
  }
}

class lichao_tree {
  struct node {
    node *ls, *rs;
    int id;

    node(int t_id) : ls(), rs(), id(t_id) {}
  };

  node *rt;

  void insert(node *&u, int l, int r, int id) {
    if (u == nullptr) {
      u = new node(id);
      return;
    }
    if (l == r) {
      if (compare(id, u->id, l) > 0) {
        u->id = id;
        return;
      }
    }
    int mid = (l + r) >> 1;
    if (compare(id, u->id, mid) > 0) {
      std::swap(id, u->id);
    }
    if (compare(id, u->id, l) > 0) {
      insert(u->ls, l, mid, id);
    } else {
      insert(u->rs, mid + 1, r, id);
    }
  }

  int query(node *u, int l, int r, int x) {
    if (u == nullptr) {
      return -1;
    }
    if (l == r) {
      return u->id;
    }
    int mid = (l + r) >> 1;
    int res;
    if (x <= mid) {
      res = query(u->ls, l, mid, x);
    } else {
      res = query(u->rs, mid + 1, r, x);
    }
    if (res == -1 || compare(u->id, res, x) > 0) {
      return u->id;
    } else {
      return res;
    }
  }

public:
  lichao_tree(int n) : rt() {
    for (int i = 0; i < n; ++i) {
      insert(rt, 1, LIM, i);
    }
    std::cout << "!" << std::endl;
  }

  void query(int x) {
    int res = query(rt, 1, LIM, x);
    std::cout << "! " << res << std::endl;
  }
};

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  std::cin >> n;
  lichao_tree T(n);
  while (true) {
    std::string tmp;
    std::cin >> tmp;
    if (tmp == "FINISH") {
      return 0;
    }
    int x;
    std::cin >> x;
    T.query(x);
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct answer

Test #2:

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

input:

6
FIRST
EQUAL
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
FIRST
QUESTION 1
SECOND
SECOND
SECOND
SECOND
QUESTION 2
EQUAL
SECOND
SECOND
SECOND
QUESTION 3
FIRST
EQUAL
SECOND
SECOND
QUESTION 4
FIRST
FIRST
EQUAL
SECOND
QUESTION 5
FIRST...

output:

? 1 0 50000
? 0 1 1
? 2 1 50000
? 1 2 1
? 3 2 50000
? 2 3 1
? 2 1 25000
? 1 2 1
? 4 3 50000
? 3 4 1
? 3 2 25000
? 2 3 1
? 2 1 12500
? 1 2 1
? 5 4 50000
? 4 5 1
? 4 3 25000
? 3 4 1
? 3 2 12500
? 2 3 1
? 2 1 6250
? 1 2 1
!
? 2 1 1
? 3 1 1
? 4 1 1
? 5 1 1
! 1
? 2 1 2
? 3 1 2
? 4 1 2
? 5 1 2
! 1
? 2 1 3...

result:

ok Correct answer

Test #3:

score: -100
Time Limit Exceeded

input:

326
SECOND
SECOND
SECOND
FIRST
FIRST
FIRST
FIRST
FIRST
SECOND
FIRST
SECOND
FIRST
FIRST
SECOND
SECOND
SECOND
SECOND
SECOND
SECOND
FIRST
SECOND
SECOND
SECOND
FIRST
SECOND
SECOND
SECOND
SECOND
FIRST
SECOND
FIRST
SECOND
FIRST
SECOND
SECOND
SECOND
SECOND
SECOND
FIRST
SECOND
FIRST
SECOND
SECOND
SECOND
FIR...

output:

? 1 0 50000
? 1 0 1
? 2 0 50000
? 2 0 1
? 3 0 50000
? 0 3 1
? 0 2 25000
? 2 0 1
? 4 3 50000
? 4 3 1
? 4 0 25000
? 4 0 1
? 4 2 12500
? 2 4 1
? 5 3 50000
? 5 3 1
? 5 1 75000
? 5 1 50001
? 6 3 50000
? 6 3 1
? 6 0 25000
? 6 0 1
? 7 3 50000
? 7 3 1
? 7 0 25000
? 7 0 1
? 7 6 37500
? 7 6 25001
? 8 3 50000
...

result: