problem_id
stringlengths 8
8
| id
int64 107k
56M
| submission_code
stringlengths 13
515k
|
---|---|---|
abc269_e | 34,933,269 | N=int(input())
sita=1
ue=N+1
def out(a,b,c,d):
print("?",a,b,c,d, flush=True)
def ans(a,b):
print("!",a,b, flush=True)
for i in range(100):
this=(sita+ue)//2
out(1,this,1,N)
T=int(input())
if this==T:
sita=this+1
else:
ue=this
if sita==ue:
break
A=sita
sita=1
ue=N+1
for i in range(100):
this=(sita+ue)//2
out(1,N,1,this)
T=int(input())
if this==T:
sita=this+1
else:
ue=this
if sita==ue:
break
B=sita
ans(A,B) |
abc269_e | 34,932,214 | n=int(input())
def is_ok1(arg):
print("?",1,n,1,arg,flush=1)
rook=int(input())
return rook==arg-1
def bisect1(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok1(mid):
ok = mid
else:
ng = mid
return ok
ans1=bisect1(0,n+1)
def is_ok2(arg):
print("?",1,arg,1,n,flush=1)
rook=int(input())
return rook==arg-1
def bisect2(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok2(mid):
ok = mid
else:
ng = mid
return ok
ans2=bisect2(0,n+1)
print("!",ans2,ans1,flush=1) |
abc269_e | 34,932,109 | import sys
input = sys.stdin.readline
N=int(input())
MINX=1
MAXX=N
while MINX!=MAXX:
mid=(MINX+MAXX)//2
print("?",MINX,mid,1,N,flush=True)
x=int(input())
if mid-MINX+1>x:
MAXX=mid
else:
MINX=mid+1
MINY=1
MAXY=N
while MINY!=MAXY:
mid=(MINY+MAXY)//2
print("?",1,N,MINY,mid,flush=True)
x=int(input())
if mid-MINY+1>x:
MAXY=mid
else:
MINY=mid+1
print("!",MINX,MINY)
|
abc269_e | 34,931,854 | n = int(input())
u,d = 0,n
while d-u > 1:
x = (u+d)//2
print("?",u+1,x,1,n,flush=True)
c = int(input())
if c == x-u:
u = x
else:
d = x
l,r = 0,n
while r-l > 1:
x = (l+r)//2
print("?",1,n,l+1,x,flush=True)
c = int(input())
if c == x-l:
l = x
else:
r = x
print("!",u+1,l+1,flush=True) |
abc269_e | 35,565,601 | n = int(input())
u = 1
d = n
while u < d:
m = (u+d)//2
print(f"? {u} {m} {1} {n}", flush=True)
t = int(input())
if m-u+1 == t:
u = m+1
else:
d = m
l = 1
r = n
while l < r:
m = (l+r)//2
print(f"? {1} {n} {l} {m}", flush=True)
t = int(input())
if m-l+1 == t:
l = m+1
else:
r = m
print("!", u, l, flush=True) |
abc269_e | 35,643,047 | def test_output(A, B, C, D):
print("? {} {} {} {}".format(A, B, C, D), flush=True)
def answer_output(X, Y):
print("! {} {}".format(X, Y), flush=True)
N = int(input())
left = 1
right = N
while left < right:
mid = (left+right)//2
test_output(left, mid, 1, N)
ret = int(input())
if ret == mid - left + 1:
left = mid+1
else:
right = mid
ans_x = left
left = 1
right = N
while left < right:
mid = (left+right)//2
test_output(1, N, left, mid)
ret = int(input())
if ret == mid - left + 1:
left = mid+1
else:
right = mid
ans_y = left
answer_output(ans_x, ans_y) |
abc269_e | 34,950,040 | n=int(input())
def judge_i(i):
#[1,i]がすべて埋まってるか
print(f'? {1} {i} {1} {n}',flush=True)
t=int(input())
if(t==i):
return 1
return 0
def judge_j(j):
#[1,i]がすべて埋まってるか
print(f'? {1} {n} {1} {j}',flush=True)
t=int(input())
if(t==j):
return 1
return 0
l=0
r=n
while(l<r-1):
mid=(l+r)>>1
if(judge_i(mid)):
l=mid
else:
r=mid
ans_i=r
l=0
r=n
while(l<r-1):
mid=(l+r)>>1
if(judge_j(mid)):
l=mid
else:
r=mid
ans_j=r
print(f'! {ans_i} {ans_j}',flush=True) |
abc269_e | 38,690,138 | N=int(input())
l=1
r=N
while l!=r:
m=(l+r)//2
result=['?',l,m,1,N]
print(*result,flush=True)
x=int(input())
if x==m-l+1:
l=m+1
else:
r=m
if l==r:
result1=r
l=1
r=N
while l!=r:
m=(l+r)//2
result=['?',1,N,l,m]
print(*result,flush=True)
x=int(input())
if x==m-l+1:
l=m+1
else:
r=m
if r==l:
result2=r
result3=['!',result1,result2]
print(*result3,flush=True)
|
abc269_e | 37,555,471 | import re
import functools
import random
import sys
import os
import math
from collections import Counter, defaultdict, deque
from functools import lru_cache, reduce
from itertools import accumulate, combinations, permutations
from heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush
from io import BytesIO, IOBase
from copy import deepcopy
import threading
import bisect
BUFSIZE = 4096
inf = float('inf')
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin = IOWrapper(sys.stdin)
sys.stdout = IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def query(a, b, c, d):
print('?', a, b, c, d)
sys.stdout.flush()
return II()
n = II()
l, r = 1, n
while l <= r:
m = (l + r) // 2
res = query(1, m, 1, n)
if res == m: l = m + 1
else: r = m - 1
x = l
l, r = 1, n
while l <= r:
m = (l + r) // 2
res = query(1, n, 1, m)
if res == m: l = m + 1
else: r = m - 1
y = l
print('!', x, y) |
abc269_e | 37,561,481 | n = int(input())
left = 1
right = n
while left < right:
mid = (left + right)//2
print('? ' + '1 ' + str(mid) + ' ' + '1 ' + str(n),flush=True)
ans = int(input())
if ans == mid:
left = mid + 1
else:
right = mid
target = right
left = 1
right = n
while left < right:
mid = (left + right)//2
print('? 1 ' + str(n) + ' ' + '1 ' + str(mid),flush=True)
ans = int(input())
if ans == mid:
left = mid + 1
else:
right = mid
print('!',target,right) |
abc269_e | 37,561,637 | n = int(input())
left = 1
right = n
while left <= right:
mid = (left + right)//2
print('? ' + '1 ' + str(mid) + ' ' + '1 ' + str(n),flush=True)
ans = int(input())
if ans == mid:
left = mid + 1
else:
right = mid - 1
target = left
left = 1
right = n
while left <= right:
mid = (left + right)//2
print('? 1 ' + str(n) + ' ' + '1 ' + str(mid),flush=True)
ans = int(input())
if ans == mid:
left = mid + 1
else:
right = mid - 1
print('!',target,left) |
abc269_e | 52,944,358 | import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
n = int(input())
#alist = list(map(int,input().split()))
#alist = []
#s = input()
#n,m = map(int,input().split())
#for i in range(n):
# alist.append(list(map(int,input().split())))
class ni():
def __init__(self):
self.n = n
def __len__(self):
return self.n
def __getitem__(self,x):
print('?',1,x+1,1,n,flush=True)
z = int(input())
if z == x+1:
return 0
else:
return 1
a = bisect.bisect_right(ni(),0)
a
class ni():
def __init__(self):
self.n = n
def __len__(self):
return self.n
def __getitem__(self,x):
print('?',1,n,1,x+1,flush=True)
z = int(input())
if z == x+1:
return 0
else:
return 1
b = bisect.bisect_right(ni(),0)
print('!',a+1,b+1) |
abc269_e | 35,583,796 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
if heap and item < heap[0]:
item, heap[0] = heap[0], item
heapq._siftup_max(heap, 0)
return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write
def Interactive(*query):
print(*query)
sys.stdout.flush()
return readline().rstrip()
def Bisect_Int(ok,ng,is_ok):
while abs(ok-ng)>1:
mid=(ok+ng)//2
if is_ok(mid):
ok=mid
else:
ng=mid
return ok
N=int(readline())
def is_ok(x):
return int(Interactive("?",1,x,1,N))!=x
X=Bisect_Int(N,0,is_ok)
def is_ok(y):
return int(Interactive("?",1,N,1,y))!=y
Y=Bisect_Int(N,0,is_ok)
print("!",X,Y) |
abc269_e | 34,938,197 | n = int(input())
rng = 0; rok = n
while rok-rng > 1:
rmid = (rng+rok)//2
print("?", rng+1, rmid, 1, n)
if int(input()) == rmid-rng: rng = rmid
else: rok = rmid
cng = 0; cok = n
while cok-cng > 1:
cmid = (cng+cok)//2
print("?", 1, n, cng+1, cmid)
if int(input()) == cmid-cng: cng = cmid
else: cok = cmid
print("!", rok, cok) |
abc269_e | 34,937,272 | import sys
sys.setrecursionlimit(10 ** 9) # Codeforcesでは350000程度に
def input():
return sys.stdin.readline().strip()
n = int(input())
l = 1
r = n
while abs(r - l) > 0:
mi = (r - l) // 2 + l
print(f"? {l} {mi} 1 {n}", flush=True)
t = int(input())
if l == mi:
break
if t == mi - l + 1:
l, r = mi + 1, r
else:
l, r = l, mi
if t == 0:
x = mi
else:
x = mi + 1
# print(l, r)
# print(x)
l = 1
r = n
while abs(r - l) > 0:
mi = (r - l) // 2 + l
print(f"? 1 {n} {l} {mi}", flush=True)
t = int(input())
if l == mi:
break
if t == mi - l + 1:
l, r = mi + 1, r
else:
l, r = l, mi
if t == 0:
y = mi
else:
y = mi + 1
# print(l, r)
print("!", x, y)
|
abc269_e | 34,931,515 | import sys, random
input = lambda : sys.stdin.readline().rstrip()
write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()]
def debug(_l_):
for s in _l_.split():
print(f"{s}={eval(s)}", end=" ")
print()
def dlist(*l, fill=0):
if len(l)==1:
return [fill]*l[0]
ll = l[1:]
return [dlist(*ll, fill=fill) for _ in range(l[0])]
# 標準出力による質問 interactive
TEST = 0
import sys
def _q(a,b,c,d):
if a==b or c==d:
return 0
print("?", a+1, b, c+1, d)
sys.stdout.flush()
val = int(input())
return val
def answer(x,y):
print(f"! {x} {y}")
sys.stdout.flush()
n = int(input())
if TEST:
import random
_x = random.randint(0,n-1)
_y = random.randint(0,n-1)
def _q(a,b,c,d):
if a==0 and b==n:
if c<=_y<d:
return d-c-1
else:
return d-c
else:
if a<=_x<b:
return b-a-1
else:
return b-a
l = 0
r = n
while abs(l-r)>1:
mm = (l+r)//2
res = _q(0,n,l,mm)
if mm-l==res:
l = mm
else:
r = mm
y = l
l = 0
r = n
while abs(l-r)>1:
mm = (l+r)//2
res = _q(l,mm,0,n)
if mm-l==res:
l = mm
else:
r = mm
x = l
answer(x+1,y+1)
if TEST:
assert x==_x and y==_y |
abc269_e | 34,935,835 | n=int(input())
ok=n
ng=0
while abs(ok-ng)>1:
num=(ok+ng)//2
print("?",1,num,1,n,flush=True)
t=int(input())
if t==num-1:
ok=num
else:
ng=num
x=ok
ok=n
ng=0
while abs(ok-ng)>1:
num=(ok+ng)//2
print("?",1,n,1,num,flush=True)
t=int(input())
if t==num-1:
ok=num
else:
ng=num
y=ok
print("!",x,y,flush=True)
|
abc269_e | 34,976,468 | n = int(input())
up = 1
down = n + 1
while (down - up) > 1:
mid = (up + down) // 2
print("?", mid, down - 1, 1, n)
if int(input()) == (down - mid):
down = mid
else:
up = mid
left = 1
right = n + 1
while (right - left) > 1:
mid = (right + left) // 2
print("?", 1, n, mid, right - 1)
if int(input()) == (right - mid):
right = mid
else:
left = mid
print("!", up, left)
|
abc269_e | 34,938,755 | def query(A: int, B: int, C: int, D: int) -> int:
print("?", A + 1, B + 1, C + 1, D + 1)
T = int(input())
assert T != -1
return T
def answer(X: int, Y: int):
print("!", X + 1, Y + 1)
exit()
N = int(input())
l = 0
r = N - 1
while l < r:
m = (l + r) // 2
if m - l + 1 > query(l, m, 0, N - 1):
r = m
else:
l = m + 1
X = l
l = 0
r = N - 1
while l < r:
m = (l + r) // 2
if m - l + 1 > query(0, N - 1, l, m):
r = m
else:
l = m + 1
Y = l
answer(X, Y)
|
abc269_e | 34,936,117 |
"""
"""
import sys
from sys import stdin
N = int(stdin.readline())
L1 = 0
R1 = N
while R1-L1 != 1:
m = (L1+R1) // 2
print ("?" , 1 , N , 1 , m , flush=True)
get = int(stdin.readline())
assert get != -1
if get >= m:
L1 = m
else:
R1 = m
L2 = 0
R2 = N
while R2-L2 != 1:
m = (L2+R2) // 2
print ("?" , 1 , m , 1 , N , flush=True)
get = int(stdin.readline())
assert get != -1
if get >= m:
L2 = m
else:
R2 = m
print ("!",R2,R1)
|
abc269_e | 34,936,100 | n=int(input())
def ok1(lb,ub):
print(f"? {lb} {ub} 1 {n}")
t=int(input())
return t
def ok2(lb,ub):
print(f"? 1 {n} {lb} {ub}")
t=int(input())
return t
lb=1
ub=n
cur=n-1
while lb<ub:
mid=(ub+lb)//2
res = ok1(lb,mid)
if res>cur//2:
lb=mid+1
cur-=res
else:
ub=mid
cur=res
i=lb
lb=1
ub=n
cur=n-1
while lb<ub:
mid=(ub+lb)//2
res = ok2(lb,mid)
if res>cur//2:
lb=mid+1
cur-=res
else:
ub=mid
cur=res
j=lb
print(f"! {i} {j}") |
abc269_e | 34,976,535 | import sys
n = int(input())
l = 0
r = n
while r > l + 1:
m = (r+l)//2
print("?",1,n,1,m)
sys.stdout.flush()
t = int(input())
if t == m:
l = m
else:
r = m
x = r
l = 0
r = n
while r > l + 1:
m = (r+l)//2
print("?",1,m,1,n)
sys.stdout.flush()
t = int(input())
if t == m:
l = m
else:
r = m
y = r
print("!",y,x)
sys.stdout.flush() |
abc269_e | 34,941,549 | N = int(input())
L = 0
R = N
count = N - 1
while R - L > 1:
M = (R + L) // 2
print(f'? {L + 1} {M} {1} {N}', flush=True)
T = int(input())
if T == -1: exit()
if (M - L) - T >= (R - M) - (count - T):
R = M
count = T
else:
L = M
count -= T
i = L + 1
L = 0
R = N
count = N - 1
while R - L > 1:
M = (R + L) // 2
print(f'? {1} {N} {L + 1} {M}', flush=True)
T = int(input())
if T == -1: exit()
if (M - L) - T >= (R - M) - (count - T):
R = M
count = T
else:
L = M
count -= T
j = L + 1
print(f'! {i} {j}') |
abc269_e | 34,937,430 | n = int(input())
suki = n+1
kirai = 1
while suki - kirai > 1:
targ = (suki + kirai) // 2
print(f"? {targ} {suki-1} {1} {n}", flush=True)
r = int(input())
if suki-targ != r:
kirai = targ
else:
suki = targ
xx = kirai
suki = n+1
kirai = 1
while suki - kirai > 1:
targ = (suki + kirai) // 2
print(f"? {1} {n} {targ} {suki-1}", flush=True)
r = int(input())
if suki-targ != r:
kirai = targ
else:
suki = targ
yy = kirai
print(f"! {xx} {yy}") |
abc269_e | 34,931,630 | def main():
from sys import stdin, setrecursionlimit
# setrecursionlimit(1000000)
input = stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 1000000000000000000
MOD = 1000000007
N = iinput()
L = 1
R = N
while L < R:
C = (L + R) // 2
print(f'? {L} {C} {1} {N}', flush=True)
T = iinput()
if T == C - L + 1:
L = C + 1
else:
R = C
X = L
L = 1
R = N
while L < R:
C = (L + R) // 2
print(f'? {1} {N} {L} {C}', flush=True)
T = iinput()
if T == C - L + 1:
L = C + 1
else:
R = C
Y = L
print(f'! {X} {Y}', flush=True)
main() |
abc269_e | 34,927,444 | def ask(a,b,c,d):
print('?',a,b,c,d,flush=True)
x=int(input())
return x
n=int(input())
ng,ok=0,n+1
while abs(ng-ok)>1:
mid=(ok+ng)//2
cnt=ask(1,mid,1,n)
if cnt<mid:
ok=mid
else:
ng=mid
X=ok
ng,ok=0,n+1
while abs(ng-ok)>1:
mid=(ok+ng)//2
cnt=ask(1,n,1,mid)
if cnt<mid:
ok=mid
else:
ng=mid
Y=ok
print('!',X,Y) |
abc269_e | 34,912,694 | def f(a,b,c,d):
print("?",a,b,c,d,flush=True)
return int(input())
N=int(input())
for i in range(2):
l=0
r=N
while r-l>1:
m=(l+r)//2
if i==0:
ret=f(l+1,m,1,N)
else:
ret=f(1,N,l+1,m)
if m-l==ret:
l=m
else:
r=m
if i==0: ansx=r
else: ansy=r
print("!",ansx,ansy)
|
abc269_e | 39,095,018 | N=int(input())
def solve(A,B,C,D):
#[A,B)
#[C,D)
print("?",A+1,B,C+1,D,flush=True)
return int(input())
low=0
high=N
while(high-low>1):
mid=(high+low)//2
if solve(0,N,0,mid)==mid:
low=mid
else:
high=mid
X=low
low=0
high=N
while(high-low>1):
mid=(high+low)//2
if solve(0,mid,0,N)==mid:
low=mid
else:
high=mid
Y=low
print("!",Y+1,X+1) |
abc269_e | 35,460,348 | def ask_i(a):
print("?", 1, a, 1, N)
if int(input()) == a - 1:
return 1
return 0
def ask_j(a):
print("?", 1, N, 1, a)
if int(input()) == a - 1:
return 1
return 0
def check(fn):
l, r = 0, N
while r - l > 1:
m = l + r >> 1
if fn(m):
r = m
else:
l = m
return r
N = int(input())
print("!", check(ask_i), check(ask_j)) |
abc269_e | 34,930,415 | n = int(input())
l, r = 0, n
while r - l > 1:
m = (l + r) // 2
print('?', l + 1, m, 1, n)
t = int(input())
if t == m - l:
l = m
else:
r = m
x = r
l, r = 0, n
while r - l > 1:
m = (l + r) // 2
print('?', 1, n, l + 1, m)
t = int(input())
if t == m - l:
l = m
else:
r = m
y = r
print('!', x, y) |
abc269_e | 34,929,670 | import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
INF = 2**63-1
mod = 998244353
def query(a, b, c, d):
print('?', a, b, c, d, flush=True)
ret = ii()
if ret == -1:
exit(1)
else:
return ret
def ans(x, y):
print('!', x, y, flush = True)
n = ii()
ok = n
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
r = query(1, mid, 1, n)
if r == mid - 1:
ok = mid
else:
ng = mid
x = ok
ok = n
ng = 0
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
r = query(1, n, 1, mid)
if r == mid - 1:
ok = mid
else:
ng = mid
y = ok
ans(x, y)
|
abc269_e | 34,939,730 | n=int(input())
l=1
r=n
t=1
u=n
while l!=r:
print(f'? {l} {(l+r)//2} {1} {n}')
num=int(input())
if num>=(l+r)//2-l+1:
l=(l+r)//2+1
else:
r=(l+r)//2
while t!=u:
print(f'? {1} {n} {t} {(u+t)//2}')
num=int(input())
if num>=(u+t)//2-t+1:
t=(t+u)//2+1
else:
u=(t+u)//2
print(f'! {l} {t}') |
abc269_e | 34,934,062 | def General_Binary_Increase_Search_Integer(L, R, cond, default=None):
""" 条件式が単調増加であるとき, 整数上で二部探索を行う.
L: 解の下限
R: 解の上限
cond: 条件(1変数関数, 広義単調増加を満たす)
default: Lで条件を満たさないときの返り値
"""
if not(cond(R)):
return default
if cond(L):
return L
R+=1
while R-L>1:
C=L+(R-L)//2
if cond(C):
R=C
else:
L=C
return R
def question(A,B,C,D):
print("?",A,B,C,D,flush=True)
T=int(input())
return T
def answer(X,Y):
print("!",X,Y,flush=True)
def solve():
N=int(input())
def row_check(i):
if i==N:
return True
elif i==0:
return False
T=question(1,i,1,N)
return T<i
def column_check(j):
if j==N:
return True
elif j==0:
return False
T=question(1,N,1,j)
return T<j
X=General_Binary_Increase_Search_Integer(0,N,row_check)
Y=General_Binary_Increase_Search_Integer(0,N,column_check)
answer(X,Y)
solve()
|
abc269_e | 34,933,822 | import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
def main():
N = NI()
l = 1
r = N + 1
for i in range(10):
if r - l <= 1:
break
m = (l + r) // 2
print(f"? {l} {m-1} 1 {N}")
sys.stdout.flush()
res = NI()
if res < m - l:
r = m
else:
l = m
X = l
l = 1
r = N + 1
for i in range(10):
if r - l <= 1:
break
m = (l + r) // 2
print(f"? 1 {N} {l} {m-1}")
sys.stdout.flush()
res = NI()
if res < m - l:
r = m
else:
l = m
Y = l
print(f"! {X} {Y}")
sys.stdout.flush()
if __name__ == "__main__":
main()
|
abc269_e | 34,932,847 | def ask(a, b, c, d):
print("?", a+1, b, c+1, d, flush=True)
return int(input())
n = int(input())
a, b = 0, n
while a+1 < b:
m = (a+b)//2
if ask(a, m, 0, n) == m-a:
a = m
else:
b = m
c, d = 0, n
while c+1 < d:
m = (c+d)//2
if ask(0, n, c, m) == m-c:
c = m
else:
d = m
print("!", b, d, flush=True)
|
abc269_e | 34,932,625 | import sys
input = sys.stdin.readline
n=int(input())
l=1
r=n
while r-l>0:
mid=(r+l)//2
print("?",l,mid,1,n,flush=True)
t=int(input())
if t==mid-l+1:
l=mid+1
else:
r=mid
x=l
l=1
r=n
while r-l>0:
mid=(r+l)//2
print("?",1,n,l,mid,flush=True)
t=int(input())
if t==mid-l+1:
l=mid+1
else:
r=mid
y=l
print("!",x,y,flush=True) |
abc269_e | 34,931,581 | from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def main():
n = I()
l = 0
r = n
while l+1 < r:
m = (l+r) >> 1
print(f"? 1 {m} 1 {n}", flush=True)
t = I()
if t == m:
l = m
else:
r = m
x = r
l = 0
r = n
while l+1 < r:
m = (l+r) >> 1
print(f"? 1 {n} 1 {m}", flush=True)
t = I()
if t == m:
l = m
else:
r = m
y = r
print("!",x,y)
return
if __name__ == "__main__":
main()
|
abc269_e | 34,935,583 | import sys
n = int(input())
l = 0
r = n
while r > l + 1:
m = (r+l)//2
print("?",1,n,1,m)
sys.stdout.flush()
t = int(input())
if t == m:
l = m
else:
r = m
x = r
l = 0
r = n
while r > l + 1:
m = (r+l)//2
print("?",1,m,1,n)
sys.stdout.flush()
t = int(input())
if t == m:
l = m
else:
r = m
y = r
print("!",y,x)
sys.stdout.flush() |
abc269_e | 34,935,495 | import sys
def query(A, B, C, D):
print(f"? {A+1} {B} {C+1} {D}")
sys.stdout.flush()
return int(input())
N = int(input())
l = 0
r = N
while r-l>1:
m = (l+r)//2
c = query(0, m, 0, N)
if c<m:
r = m
else:
l = m
u = 0
d = N
while d-u>1:
m = (u+d)//2
c = query(0, N, 0, m)
if c<m:
d = m
else:
u = m
print(f"! {l+1} {u+1}")
|
abc269_e | 34,935,014 | N=int(input())
left=1;right=N
while left!=right:
mid=(left+right)//2
print("?",left,mid,1,N,flush=True)
T=int(input())
if T==mid-left+1: left=mid+1 #left~midの区間には必ずルークがあるので
else: right=mid
i=left
left=1;right=N
while left!=right:
mid=(left+right)//2
print("?",1,N,left,mid,flush=True)
T=int(input())
if T==mid-left+1: left=mid+1 #left~midの区間には必ずルークがあるので
else: right=mid
j=left
print("!",i,j,flush=True)
|
abc269_e | 34,933,645 | (N,) = [int(x) for x in input().split()]
def query(A, B, C, D):
print("?", A, B, C, D, flush=True)
(ret,) = [int(x) for x in input().split()]
if ret == -1:
assert False
return ret
lo = 1
hi = N
while lo < hi:
mid = (lo + hi) // 2
if query(lo, mid, 1, N) < mid - lo + 1:
hi = mid
else:
lo = mid + 1
ansC = hi
lo = 1
hi = N
while lo < hi:
mid = (lo + hi) // 2
if query(1, N, lo, mid) < mid - lo + 1:
hi = mid
else:
lo = mid + 1
ansR = hi
print("!", ansC, ansR)
|
abc269_e | 43,541,793 | N = int(input())
A = 1
B = N
C = 1
D = N
while B - A > 0:
m = (A+B) // 2
print('?',A,m,1,N)
T = int(input())
if m - A + 1 == T:
A = m + 1
else:
B = m
while D - C > 0:
m = (C+D) // 2
print('?',1,N,C,m)
T = int(input())
if m - C + 1 == T:
C = m + 1
else:
D = m
print('!',A,C) |
abc269_e | 34,942,696 | class Solver:
def __init__(self, n):
self.n = n
self.left_i = 1
self.right_i = n
self.center_i = (self.left_i + self.right_i) // 2
self.left_j = 1
self.right_j = n
self.center_j = (self.left_j + self.right_j) // 2
self.solved_i = False
self.solved_j = False
self.ans_i = -1
self.ans_j = -1
def query(self):
if not self.solved_i:
return f"? {self.left_i} {self.center_i} {1} {self.n}"
elif not self.solved_j:
return f"? {1} {self.n} {self.left_j} {self.center_j}"
else:
return f"! {self.ans_i} {self.ans_j}"
def input(self, ans):
if ans == -1:
return "!"
elif not self.solved_i:
if ans == self.center_i - self.left_i + 1: # filled
self.left_i = self.center_i + 1
self.center_i = (self.left_i + self.right_i) // 2
else: # not filled
self.right_i = self.center_i
self.center_i = (self.left_i + self.right_i) // 2
if self.left_i == self.right_i:
self.ans_i = self.left_i
self.solved_i = True
elif not self.solved_j:
if ans == self.center_j - self.left_j + 1: # filled
self.left_j = self.center_j + 1
self.center_j = (self.left_j + self.right_j) // 2
else: # not filled
self.right_j = self.center_j
self.center_j = (self.left_j + self.right_j) // 2
if self.left_j == self.right_j:
self.ans_j = self.left_j
self.solved_j = True
def main():
n = int(input())
solver = Solver(n)
while True:
res = solver.query()
if res[0] == "!":
print(res)
break
print(res)
ans = int(input())
solver.input(ans)
if __name__ == "__main__":
main()
|
abc269_e | 47,815,647 | N=int(input())
ok=1
ng=N+1
while abs(ok-ng)>1:
mid=(ok+ng)//2
print("?",mid,N,1,N)
if int(input())==N-mid:
ok=mid
else:
ng=mid
ans1=ok
ok=1
ng=N+1
while abs(ok-ng)>1:
mid=(ok+ng)//2
print("?",1,N,mid,N)
if int(input())==N-mid:
ok=mid
else:
ng=mid
print("!",ans1,ok) |
abc269_e | 34,934,861 | n = int(input())
l = 1
r = n + 1
u = 1
d = n + 1
while r - l > 1:
m = (r + l) // 2
print("?", u, d - 1, l, m - 1)
k = int(input())
if k >= m - l:
l = m
else:
r = m
while d - u > 1:
m = (d + u) // 2
print("?", u, m - 1, 1, n)
k = int(input())
if k >= m - u:
u = m
else:
d = m
print("!", u, l) |
abc269_e | 34,930,041 | # input of n
n = int(input())
# binary search: phase 1
lx, rx = 0, n
while rx - lx > 1:
mx = (lx + rx) // 2
print('?', 1, mx, 1, n)
t = int(input())
if t == mx:
lx = mx
else:
rx = mx
# binary search: phase 2
ly, ry = 0, n
while ry - ly > 1:
my = (ly + ry) // 2
print('?', 1, n, 1, my)
t = int(input())
if t == my:
ly = my
else:
ry = my
# output
print('!', rx, ry) |
abc269_e | 34,929,861 | mod = 998244353
def main():
import sys
input = sys.stdin.readline
def ask(a, b, c, d):
print("?", a, b, c, d)
sys.stdout.flush()
return int(input())
N = int(input())
h0 = 1
h1 = N
while h0 != h1:
h = (h0 + h1) // 2
t = ask(h0, h, 1, N)
if t == h - h0 + 1:
h0 = h + 1
else:
h1 = h
w0 = 1
w1 = N
while w0 != w1:
w = (w0 + w1) // 2
t = ask(1, N, w0, w)
if t == w - w0 + 1:
w0 = w + 1
else:
w1 = w
print("!", h0, w0)
sys.stdout.flush()
if __name__ == '__main__':
main()
|
abc269_e | 34,931,090 | import sys
input = sys.stdin.readline
from collections import *
N = int(input())
l, r = 1, N
while l<=r:
m = (l+r)//2
A, B = 1, N
C, D = 1, m
print(f'? {A} {B} {C} {D}')
sys.stdout.flush()
res = int(input())
if res<m:
r = m-1
else:
l = m+1
Y = l
l, r = 1, N
while l<=r:
m = (l+r)//2
A, B = 1, m
C, D = 1, N
print(f'? {A} {B} {C} {D}')
sys.stdout.flush()
res = int(input())
if res<m:
r = m-1
else:
l = m+1
X = l
print(f'! {X} {Y}') |
abc269_e | 34,996,693 | import sys
input = sys.stdin.readline
N = int(input())
def ask(a, b, c, d):
print("?", a+1, b+1, c+1, d+1)
sys.stdout.flush()
re = int(input())
return re
r = N
l = 0
while r-l > 1:
m = (r+l)//2
c = ask(l, m-1, 0, N-1)
if c != m-l:
r = m
else:
l = m
x = r
r = N
l = 0
while r-l > 1:
m = (r+l)//2
c = ask(0, N-1, l, m-1)
if c != m-l:
r = m
else:
l = m
y = r
print("!", x, y)
sys.stdout.flush() |
abc269_e | 52,012,682 | from sys import stdin
class FastIO:
def __init__(self):
self.random_seed = 0
self.flush = False
self.inf = 1 << 32
return
@staticmethod
def read_int():
return int(stdin.readline().rstrip())
@staticmethod
def read_float():
return float(stdin.readline().rstrip())
@staticmethod
def read_list_ints():
return list(map(int, stdin.readline().rstrip().split()))
@staticmethod
def read_list_ints_minus_one():
return list(map(lambda x: int(x) - 1, stdin.readline().rstrip().split()))
@staticmethod
def read_str():
return stdin.readline().rstrip()
@staticmethod
def read_list_strs():
return stdin.readline().rstrip().split()
def get_random_seed(self):
import random
self.random_seed = random.randint(0, 10 ** 9 + 7)
return
def st(self, x):
return print(x, flush=self.flush)
def lst(self, x):
return print(*x, flush=self.flush)
def flatten(self, lst):
self.st("\n".join(str(x) for x in lst))
return
@staticmethod
def max(a, b):
return a if a > b else b
@staticmethod
def min(a, b):
return a if a < b else b
@staticmethod
def ceil(a, b):
return a // b + int(a % b != 0)
@staticmethod
def accumulate(nums):
n = len(nums)
pre = [0] * (n + 1)
for i in range(n):
pre[i + 1] = pre[i] + nums[i]
return pre
class BinarySearch:
def __init__(self):
return
@staticmethod
def find_int_left(low: int, high: int, check) -> int:
"""find the minimum int x which make check true"""
while low < high - 1:
mid = low + (high - low) // 2
if check(mid):
high = mid
else:
low = mid
return low if check(low) else high
@staticmethod
def find_int_left_strictly(low: int, high: int, check) -> int:
"""find the minimum int x which make check true"""
while low < high:
mid = low + (high - low) // 2
if check(mid):
high = mid
else:
low = mid + 1
return low
@staticmethod
def find_int_right(low: int, high: int, check) -> int:
"""find the maximum int x which make check true"""
while low < high - 1:
mid = low + (high - low) // 2
if check(mid):
low = mid
else:
high = mid
return high if check(high) else low
@staticmethod
def find_int_right_strictly(low: int, high: int, check) -> int:
"""find the maximum int x which make check true"""
while low < high:
mid = low + (high - low + 1) // 2
if check(mid):
low = mid
else:
high = mid - 1
return high
@staticmethod
def find_float_left(low: float, high: float, check, error=1e-6) -> float:
"""find the minimum float x which make check true"""
while low < high - error:
mid = low + (high - low) / 2
if check(mid):
high = mid
else:
low = mid
return low if check(low) else high
@staticmethod
def find_float_right(low: float, high: float, check, error=1e-6) -> float:
"""find the maximum float x which make check true"""
while low < high - error:
mid = low + (high - low) / 2
if check(mid):
low = mid
else:
high = mid
return high if check(high) else low
class Solution:
def __init__(self):
return
@staticmethod
def main(ac=FastIO()):
"""
url: url of the problem
tag: algorithm tag
"""
ac.flush = True
n = ac.read_int()
def check(x):
ac.lst(["?"] + [1, x + 1, 1, n])
cnt = ac.read_int()
return cnt < x + 1
def check2(x):
ac.lst(["?"] + [1, n, 1, x + 1])
cnt = ac.read_int()
return cnt < x + 1
row = BinarySearch().find_int_left_strictly(0, n - 1, check)
col = BinarySearch().find_int_left_strictly(0, n - 1, check2)
ac.lst(["!", row + 1, col + 1])
return
Solution().main()
|
abc269_e | 52,013,480 | from sys import stdin
class FastIO:
def __init__(self):
self.random_seed = 0
self.flush = False
self.inf = 1 << 32
return
@staticmethod
def read_int():
return int(stdin.readline().rstrip())
@staticmethod
def read_float():
return float(stdin.readline().rstrip())
@staticmethod
def read_list_ints():
return list(map(int, stdin.readline().rstrip().split()))
@staticmethod
def read_list_ints_minus_one():
return list(map(lambda x: int(x) - 1, stdin.readline().rstrip().split()))
@staticmethod
def read_str():
return stdin.readline().rstrip()
@staticmethod
def read_list_strs():
return stdin.readline().rstrip().split()
def get_random_seed(self):
import random
self.random_seed = random.randint(0, 10 ** 9 + 7)
return
def st(self, x):
return print(x, flush=self.flush)
def lst(self, x):
return print(*x, flush=self.flush)
def flatten(self, lst):
self.st("\n".join(str(x) for x in lst))
return
@staticmethod
def max(a, b):
return a if a > b else b
@staticmethod
def min(a, b):
return a if a < b else b
@staticmethod
def ceil(a, b):
return a // b + int(a % b != 0)
@staticmethod
def accumulate(nums):
n = len(nums)
pre = [0] * (n + 1)
for i in range(n):
pre[i + 1] = pre[i] + nums[i]
return pre
class BinarySearch:
def __init__(self):
return
@staticmethod
def find_int_left(low: int, high: int, check) -> int:
"""find the minimum int x which make check true"""
while low < high - 1:
mid = low + (high - low) // 2
if check(mid):
high = mid
else:
low = mid
return low if check(low) else high
@staticmethod
def find_int_left_strictly(low: int, high: int, check) -> int:
"""find the minimum int x which make check true"""
while low < high:
mid = low + (high - low) // 2
if check(mid):
high = mid
else:
low = mid + 1
return low
@staticmethod
def find_int_right(low: int, high: int, check) -> int:
"""find the maximum int x which make check true"""
while low < high - 1:
mid = low + (high - low) // 2
if check(mid):
low = mid
else:
high = mid
return high if check(high) else low
@staticmethod
def find_int_right_strictly(low: int, high: int, check) -> int:
"""find the maximum int x which make check true"""
while low < high:
mid = low + (high - low + 1) // 2
if check(mid):
low = mid
else:
high = mid - 1
return high
@staticmethod
def find_float_left(low: float, high: float, check, error=1e-6) -> float:
"""find the minimum float x which make check true"""
while low < high - error:
mid = low + (high - low) / 2
if check(mid):
high = mid
else:
low = mid
return low if check(low) else high
@staticmethod
def find_float_right(low: float, high: float, check, error=1e-6) -> float:
"""find the maximum float x which make check true"""
while low < high - error:
mid = low + (high - low) / 2
if check(mid):
low = mid
else:
high = mid
return high if check(high) else low
class Solution:
def __init__(self):
return
@staticmethod
def main(ac=FastIO()):
"""
url: https://atcoder.jp/contests/abc269/tasks/abc269_e
tag: binary_search_strictly|interactive|classical
"""
ac.flush = True
n = ac.read_int()
def check1(x):
ac.lst(["?"] + [1, x + 1, 1, n])
cnt = ac.read_int()
return cnt < x + 1
def check2(x):
ac.lst(["?"] + [1, n, 1, x + 1])
cnt = ac.read_int()
return cnt < x + 1
row = BinarySearch().find_int_left_strictly(0, n - 1, check1)
col = BinarySearch().find_int_left_strictly(0, n - 1, check2)
ac.lst(["!", row + 1, col + 1])
return
Solution().main()
|
abc269_e | 35,061,469 | import sys
N = int(input())
m=1
M=N+1
while m+1<M:
temp=(m+M)//2
print("?",1,N,m,temp-1)
sys.stdout.flush()
r = int(input())
if r==temp-m:
m=temp
else:
M=temp
ans1 = m
m=1
M=N+1
while m+1<M:
temp=(m+M)//2
print("?",m,temp-1,1,N)
sys.stdout.flush()
r = int(input())
if r==temp-m:
m=temp
else:
M=temp
ans2 = m
print("!",ans2,ans1) |
abc269_e | 34,966,575 | N=int(input())
st=0
en=N+1
while en-st>1:
mid=(st+en)//2
print("?",1,mid,1,N)
if int(input())==mid:
st=mid
else:
en=mid
X=en
st=0
en=N+1
while en-st>1:
mid=(st+en)//2
print("?",1,N,1,mid)
if int(input())==mid:
st=mid
else:
en=mid
Y=en
print("!",X,Y)
|
abc269_e | 34,941,911 | import sys
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
def input(): return sys.stdin.readline().rstrip()
def Yes(b): return bool([print('Yes')] if b else print('No'))
def YES(b): return bool([print('YES')] if b else print('NO'))
def int1(x): return int(x) - 1
N = int(input())
def nibutan(ok, ng):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid, ok):
ok = mid
else:
ng = mid
return ok
def solve(mid, ok):
print(f"? {ok} {mid-1} 1 {N}")
sys.stdout.flush()
T = int(input())
return T == mid - ok
y = nibutan(1, N + 1)
def nibutan_(ok, ng):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve_(mid, ok):
ok = mid
else:
ng = mid
return ok
def solve_(mid, ok):
print(f"? 1 {N} {ok} {mid-1}")
sys.stdout.flush()
T = int(input())
return T == mid - ok
x = nibutan_(1, N + 1)
print(f"! {y} {x}")
|