QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107548 | #6394. Turn on the Light | wsyear | WA | 3ms | 3512kb | C++17 | 1.6kb | 2023-05-21 22:34:42 | 2023-05-21 22:34:43 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define gc getchar
#define pc putchar
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using namespace std;
template <class T = int> T read() {
T x = 0; bool f = 0; char ch = gc();
while (!isdigit(ch)) f = ch == '-', ch = gc();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = gc();
return f ? -x: x;
}
template <class T> void write(T x) {
if (x >= 0) { if (x > 9) write(x / 10); pc(x % 10 + 48); }
else { pc('-'); if (x < -9) write(-x / 10); pc(48 - x % 10); }
}
int n;
int ask(int x) {
printf("? %d\n", x), fflush(stdout);
return read();
}
void rpt(int x) {
printf("! %d\n", x), fflush(stdout);
}
int main() {
n = read();
int l = 2, r = n, lst = ask(1);
if (!lst) return rpt(1), 0;
while (l <= r) {
int mid = (l + r) >> 1;
int cur = ask(mid);
if (cur == lst) return rpt(mid), 0;
if (cur > lst) l = mid + 1;
else r = mid - 1;
lst = cur;
if (l < r && lst != 0) {
cur = ask(l);
if (cur == lst) return rpt(l), 0;
l++, lst = cur;
}
}
rpt(l);
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3512kb
input:
3 1 2 2
output:
? 1 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3464kb
input:
10 1 0 1 2 3
output:
? 1 ? 6 ? 3 ? 4 ? 5 ! 6
result:
wrong answer Wrong favorite light!