QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#113889 | #866. Display of Springs | Hongzy | TL | 0ms | 0kb | C++14 | 2.0kb | 2023-06-19 23:31:49 | 2023-06-19 23:31:52 |
Judging History
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() {
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