Untitled
unknown
python
3 years ago
1.5 kB
8
Indexable
#bài 4
from sys import stdin, stdout
def operation(ds):
while True:
operator = []
while len(operator) == 0:
operator = list(map(int, stdin.readline().strip().split()))
if operator[0]==1:
ds[operator[1]]=1
elif operator[0]==2:
if operator[1] in ds:
stdout.write("1\n")
else:
stdout.write("0\n")
elif operator[0]==3:
if operator[1] in ds:
ds.pop(operator[1])
elif operator[0] == 0:
return
ds= {}
operation(ds)
#bài 2
import bisect
from sys import stdin
def k_array(ds, k, x):
loc = bisect.bisect_left(ds,x)
if k >= len(ds):
return ds[0], ds[-1]
if loc==len(ds):
loc -= 1
l, r = loc, loc+1
i=0
while i<k:
if l<0:
l=-1
r=k
break
elif r >=len(ds):
r = len(ds)
l = r-1-k
break
else:
if ( x- ds[l] ) <= (ds[r]-x):
l-=1
else:
r+=1
i+=1
return ds[l+1], ds[r-1]
n = int(input())
ds = list(map(int,stdin.readline().strip().split()))
k,x=[],[]
try:
while True:
temp_k, temp_x = map(int, input().split())
#temp1=k_array(ds,temp_k, temp_x)
k.append(temp_k),x.append(temp_x)
except:
pass
for index, num in enumerate(x):
temp1 = k_array(ds, k[index], num)
print(temp1[0], temp1[-1])Editor is loading...