#include <bits/stdc++.h>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define int long long
#define endl '\n'
using namespace std;
const int MAXN = 1e18;
int mod = 1e9 + 7;
struct data
{
int a,b,c;
string s;
};
int ask(int l,int r)
{
cout << "? " << l << " " << r << endl;
int res;
cin >> res;
return res;
}
void AcSolution()
{
int n;
cin >> n;
int l = 1;
int r = n;
while(l < r)
{
if(r - l == 1)
{
int ans1 = ask(l,r);
if(ans1 == r)
{
cout << "! " << l << endl;
}
else
{
cout << "! " << r << endl;
}
return;
}
int mid = (l + r) / 2;
int ans1 = ask(l,r);
if(ans1 < mid)
{
int ans2 = ask(l,mid);
if(ans2 == ans1)
{
r = mid;
}
else
{
l = mid + 1;
}
}
else
{
int ans2 = ask(mid,r);
if(ans2 == ans1)
{
l = mid;
}
else
{
r = mid - 1;
}
}
}
cout << "! " << l << endl;
}
signed main()
{
int t = 1;
// cin >> t;
while(t--)
{
AcSolution();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |