QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113887#866. Display of SpringsHongzyTL 0ms0kbC++142.0kb2023-06-19 23:28:012023-06-19 23:28:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-19 23:28:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-06-19 23:28:01]
  • 提交

answer

#include <bits/stdc++.h>
#define LOG(FMT...) fprintf(stderr, FMT);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;

#define fs first
#define sc second
#define pb push_back
#define mp make_pair

using db = double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 1e5 + 5, M = 100000;
const int mod = 1e9 + 7;

int id[N << 2];
int query(int x, int y, int w) {
  cout << "? " << x << " " << y << " " << w << endl;
  string s;
  cin >> s;
  if(s == "FIRST") return -1;
  if(s == "SECOND") return 1;
  return 0;
}
int Min(int x, int y, int w) {
  if(!x || !y) return x | y;
  return query(x, y, w) == -1 ? x : y;
}
void modify(int u, int l, int r, int cur) {
  if(!id[u]) {
    id[u] = cur;
    return ;
  }
  if(l == r) {
    id[u] = Min(id[u], cur, l);
    return ;
  }
  int m1 = Min(id[u], cur, l);
  int m2 = Min(id[u], cur, r);
  if(m1 == id[u] && m2 == id[u]) return ;
  if(m1 == cur && m2 == cur) {
    id[u] = cur;
    return ;
  }

  int mid = (l + r) >> 1;
  if(Min(id[u], cur, mid) == cur) {
    if(m1 == id[u]) modify(u << 1, l, mid, id[u]);
    else modify(u << 1 | 1, mid + 1, r, id[u]);
    id[u] = cur;
  } else {
    if(m1 == cur) modify(u << 1, l, mid, cur);
    else modify(u << 1 | 1, mid + 1, r, cur);
  }
}
int ans;
void solve(int u, int l, int r, int w) {
  ans = Min(ans, id[u], w);
  if(l == r) {
    return ;
  }
  int mid = (l + r) >> 1;
  if(w <= mid) solve(u << 1, l, mid, w);
  else solve(u << 1 | 1, mid + 1, r, w);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  rep(i, 1, n) {
    modify(1, 1, M, i);
  }
  cout << "!" << endl;
  while(1) {
    string s;
    cin >> s;
    if(s == "FINISH")
      break;
    int w;
    cin >> w;
    ans = 0;
    solve(1, 1, M, w);
    cout << "! " << ans << endl;
  }
  return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
FIRST
SECOND
SECOND

output:

? 1 2 1
? 1 2 100000
? 1 2 50000
? 2 3 1

result: