-
Notifications
You must be signed in to change notification settings - Fork 0
/
1486C2.py
101 lines (94 loc) · 2.12 KB
/
1486C2.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#######puzzleVerma#######
import sys
import math
mod = 10**9+7
LI=lambda:[int(k) for k in input().split()]
input = lambda: sys.stdin.readline().rstrip()
IN=lambda:int(input())
S=lambda:input()
r=range
n=IN()
print("?",1,n,flush=True)
ans=IN()
if n==2:
if ans==2:
print("!",1,flush=True)
else:
print("!",2,flush=True)
sys.exit()
if (ans==1):
a=ans-1
elif (ans==n):
a=ans
else:
print("?",1,ans,flush=True)
a=IN()
if a==ans:
st=1
en=ans
while en-st>1:
mid=(st+en)//2
# if mid==ans:
# print("!",ans-1,flush=True)
# sys.exit()
# if mid==st:
# print("?",en,ans,flush=True)
# a=IN()
# if a==ans:
# print("!",en,flush=True)
# else:
# print("!",st,flush=True)
# sys.exit()
print("?",mid,ans,flush=True)
a=IN()
if a==ans:
st=mid
else:
en=mid-1
if en==ans:
print("!",st,flush=True)
sys.exit()
if en==(st+1):
print("?",en,ans,flush=True)
a=IN()
if a==ans:
print("!",en,flush=True)
else:
print("!",st,flush=True)
sys.exit()
print("!",en,flush=True)
else:
st=ans
en=n
while en-st>1:
mid=(st+en)//2
# if mid==ans:
# print("!",ans+1,flush=True)
# sys.exit()
# if mid==st:
# print("?",ans,st,flush=True)
# a=IN()
# if a==ans:
# print("!",st,flush=True)
# else:
# print("!",en,flush=True)
# sys.exit()
print("?",ans,mid,flush=True)
a=IN()
if a==ans:
en=mid
else:
st=mid+1
if st==ans:
print("!",en,flush=True)
sys.exit()
if en==(st+1):
print("?",ans,st,flush=True)
a=IN()
if a==ans:
print("!",st,flush=True)
else:
print("!",en,flush=True)
sys.exit()
print("!",st,flush=True)
sys.exit()