QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402434 | #6394. Turn on the Light | iwew | WA | 1ms | 3708kb | C++20 | 1.5kb | 2024-04-30 16:00:04 | 2024-04-30 16:00:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
bool vis[N];
int ask(int x) {
cout << "? " << x << endl;
int t;
cin >> t;
return t;
}
void dfs(int L, int R, int &ans, int lstd) {
int tmp = ask((L + R) >> 1);
if(tmp == lstd) {
ans = (L + R) >> 1;
return;
}
auto take = [&](auto &&take, int l, int r, bool dir, int &nowd) -> void {
int mid = (l + r) >> 1;
auto curd = ask(mid);
if(curd == nowd) {
ans = mid;
return;
}
if(l == r) {
nowd = curd;
return;
}
if(curd > nowd) {
if(dir) take(take, l, mid - 1, dir, curd);
else take(take, mid + 1, r, dir, curd);
}
else {
if(curd == 0) {
if(dir) dfs(mid + 1, r, ans, curd);
else dfs(l, mid - 1, ans, curd);
} else {
if(dir) take(take, mid + 1, r, dir, curd);
else take(take, l, mid - 1, dir, curd);
}
}
nowd = curd;
};
take(take, L, ((L + R) >> 1) - 1, true, tmp);
if(ans != -1) return;
take(take, ((L + R) >> 1) + 1, R, false, tmp);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = -1;
dfs(1, n, ans, 0);
cout << "! " << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3700kb
input:
3 1 2 2
output:
? 2 ? 1 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 1 2 3 2 3 3
output:
? 5 ? 2 ? 1 ? 8 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #3:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
9 1 2 3 4 5 5
output:
? 5 ? 2 ? 1 ? 7 ? 8 ? 9 ! 9
result:
ok Correct position at 9
Test #4:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
8 1 2 3 4 5 5
output:
? 4 ? 2 ? 1 ? 6 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #5:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
7 1 2 3 2 2
output:
? 4 ? 2 ? 1 ? 6 ? 5 ! 5
result:
ok Correct position at 5
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3652kb
input:
6 1 2
output:
? 3 ? 1 ? 0
result:
wrong answer Integer parameter [name=x] equals to 0, violates the range [1, 6]