QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#378687 | #6394. Turn on the Light | gogo11# | WA | 1ms | 3704kb | C++17 | 1.8kb | 2024-04-06 14:11:50 | 2024-04-06 14:11:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ui = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define lowbit(x) ((x) & (-x))
constexpr int N = 2e5 + 10;
constexpr int M = 5e5 + 10;
constexpr ll mod = (1LL<<20);
constexpr int INF = 0x3f3f3f3f;
constexpr ll Base = 131;
constexpr int MAXBIT = 19;
int ans;
int query(int x) {
cout << "? " << x << endl;
int res;
cin >> res;
return res;
}
void print(int ans)
{
cout << "! " << ans << endl;
}
void solve()
{
int n;
cin >> n;
ans = 0;
int l = 1, r = n;
while(1)
{
int mid = l + r >> 1;
if(ans == 0)
{
ll t = query(mid);
if(t == ans)
{
// cout << mid << endl;
print(mid);
return;
}
else
{
t = query(l);
if(t == 1)
{
// cout << mid << endl;
print(mid);
return;
}
else if(t == 2) l = mid + 1;
else if(t == 0) ++ l, r = mid - 1;
}
ans = t;
continue;
}
ll t = query(mid);
if(t == ans)
{
// cout << mid << endl;
print(mid);
return;
}
else if(t > ans) l = mid + 1;
else r = mid - 1;
ans = t;
}
}
int main()
{
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// #endif
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3620kb
input:
3 1 2 2
output:
? 2 ? 1 ? 3 ! 3
result:
ok Correct position at 3
Test #2:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
10 1 2 3 3
output:
? 5 ? 1 ? 8 ? 9 ! 9
result:
ok Correct position at 9
Test #3:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
9 1 2 3 3
output:
? 5 ? 1 ? 7 ? 8 ! 8
result:
ok Correct position at 8
Test #4:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
8 1 2 3 3
output:
? 4 ? 1 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #5:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
7 1 2 3 3
output:
? 4 ? 1 ? 6 ? 7 ! 7
result:
ok Correct position at 7
Test #6:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
6 1 2 3 3
output:
? 3 ? 1 ? 5 ? 6 ! 6
result:
ok Correct position at 6
Test #7:
score: 0
Accepted
time: 1ms
memory: 3700kb
input:
5 1 2 3 3
output:
? 3 ? 1 ? 4 ? 5 ! 5
result:
ok Correct position at 5
Test #8:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
4 1 2 3 3
output:
? 2 ? 1 ? 3 ? 4 ! 4
result:
ok Correct position at 4
Test #9:
score: -100
Wrong Answer
time: 0ms
memory: 3608kb
input:
3 1 1
output:
? 2 ? 1 ! 2
result:
wrong answer Wrong favorite light!