-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path10.cpp
71 lines (62 loc) · 1.1 KB
/
10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// JAI BAJARANG BALI
// manitianajay45
// give me some sun shine, give me some rain, give me some little more chance to grow up once again
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll ask(ll l, ll r)
{
if (l >= r)
{
return -1;
}
cout<<"? "<<l+1<<" "<<r+1<<endl;
ll val;
cin>>val;
return val-1;
}
int main()
{
ll n;
cin>>n;
ll smax;
smax=ask(0,n-1);
ll l,r;
if(smax==0 || ask(0,smax)!=smax)
{
l=smax;
r=n-1;
ll m;
while(r-l>1)
{
m=(l+r)/2;
if(ask(smax,m)==smax)
{
r=m;
}else
{
l=m;
}
}
cout<<"! "<<r+1<<endl;
}else
{
l=0;
r=smax;
ll m;
while(r-l>1)
{
m=(l+r)/2;
if(ask(m,smax)==smax)
{
l=m;
}else
{
r=m;
}
}
cout<<"! "<<l+1<<endl;
}
return 0;
}