QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470376 | #6394. Turn on the Light | UESTC_DebugSimulator# | WA | 1ms | 3752kb | C++17 | 882b | 2024-07-10 12:25:42 | 2024-07-10 12:25:42 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
int n, x;
void ask(int k) {
cout << "? " << k << endl;
cin >> x;
}
void solve() {
cin >> n;
ask(1);
if (!x) {
cout << "! 1" << endl;
return;
}
int l = 2, r = n, last = x;
while(l < r) {
int mid = (l + r)>>1;
ask(mid);
if (last == x) {
cout << "! " << mid << endl;
return;
}
if (last) {
if (x > last) l = mid + 1;
else r = mid;
}
else {
last = x;
ask(l);
l++;
if (last == x) {
cout << "! " << mid << endl;
return;
}
if (x < last) r = mid;
else l = mid + 1;
}
last = x;
}
cout << "! " << l << endl;
}
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
3 1 2
output:
? 1 ? 2 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
10 1 0 1 0 0
output:
? 1 ? 6 ? 4 ? 2 ? 3 ! 3
result:
ok Correct position at 3
Test #3:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
9 1 2 3 3
output:
? 1 ? 5 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3752kb
input:
8 1 0 1 1
output:
? 1 ? 5 ? 3 ? 2 ! 3
result:
wrong answer Wrong favorite light!