Problem p03033 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n,Q=map(int,input().split())
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,input().split())
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(input()),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            print(segl[0] if segl[0]!= mx else -1)
            continue
        update(x[3], x[2] if x[1] else mx)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,Q=map(int,input().split())
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 
def update(k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,input().split())
        xs += [(s-x,True,x,i), (t-x,False,x,i)]
    qs = []
    for _ in range(Q):
        qs.append(int(input()))
    xs.sort(key=lambda x:x[0])
    j = 0
    for x in xs:
        while True:
            if qs[j] < x[0]:
                print(segl[0] if segl[0]!= mx else -1)
                j += 1
                continue
            break
        update(x[3], x[2] if x[1] else mx)
    while Q-j:
        print(-1)
        j+=1

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,Q=map(int,input().split())
bn = 17
b_num = 131072
mx = 10**9
segl=[mx]*2*b_num 

#xs = [[int(c) for c in input().split()] for _ in range(n)]
xs = []
for i in range(n):
    s,t,x=[int(c) for c in input().split()]
    xs += [(s-x,0,x,i), (t-x,1,x,i)]
for _ in range(Q):
    xs.append((int(input()),2,0,0))
xs.sort()
ys = set()
for x in xs:
    if x[1]==2:
        for _ in range(bn):
            nys = set()
            ys = nys
        print(segl[0] if segl[0]!= mx else -1)
        ys = set()
        continue
    segl[x[3]+b_num-1] = mx if x[1] else x[2]
    ys.add((x[3]+b_num-2)//2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,Q=map(int,input().split())
bn = (n-1).bit_length()
b_num = 2**bn
mx = 10**9
segl=[mx]*2*b_num 

xs = []
for s, t, x in [[int(c) for c in input().split()] for _ in range(n)]:
    xs += [(s-x,0,x,i), (t-x,1,x,i)]
for _ in range(Q):
    xs.append((int(input()),2,0,0))
xs.sort()
ys = set()
for x in xs:
    if x[1]==2:
        for _ in range(bn):
            nys = set()
            ys = nys
        print(segl[0] if segl[0]!= mx else -1)
        ys = set()
        continue
    segl[x[3]+b_num-1] = mx if x[1] else x[2]
    ys.add((x[3]+b_num-2)//2)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n,Q=map(int,input().split())
bn = (n-1).bit_length()
b_num = 2**bn
mx = 10**9
segl=[mx]*2*b_num 

#xs = [[int(c) for c in input().split()] for _ in range(n)]
for i in range(n):
    s,t,x=[int(c) for c in input().split()]
    xs += [(s-x,0,x,i), (t-x,1,x,i)]
for _ in range(Q):
    xs.append((int(input()),2,0,0))
xs.sort()
ys = set()
for x in xs:
    if x[1]==2:
        for _ in range(bn):
            nys = set()
            ys = nys
        print(segl[0] if segl[0]!= mx else -1)
        ys = set()
        continue
    segl[x[3]+b_num-1] = mx if x[1] else x[2]
    ys.add((x[3]+b_num-2)//2)

Buggy submission (verdict: Runtime Error):
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs = []
for _ in range(n):
    s,t,x=map(int,input().split())
    xs += [(s-x-0.5,True,x), (t-x-0.5,False,x)]
xs.sort(key=lambda x:x[0])
xs += [(10**9,True,x)]

h=set()
q = int(input())
for t,r,x in xs:
    if q < t:
        if h:
            c = min(h)
        else:
            c = -1
        while True:
            if q >= t:
                break
            print(c)
            Q-=1
            if not Q:
                sys.exit()
            q = int(input())
    if r:
        h.add(x)
    else:
        h.remove(x)

Buggy submission (verdict: Runtime Error):
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs = []
for _ in range(n):
    s,t,x=map(int,input().split())
    xs += [(s-x-0.5,True,x), (t-x-0.5,False,x)]
xs.sort(key=lambda x:x[0])
xs += [(t-x,True,x)]

h=set()
q = int(input())
for t,r,x in xs:
    if q < t:
        if h:
            c = min(h)
        else:
            c = -1
        while True:
            if q >= t:
                break
            print(c)
            Q-=1
            if not Q:
                sys.exit()
            q = int(input())
    if r:
        h.add(x)
    else:
        h.remove(x)

Buggy submission (verdict: Runtime Error):
# ABC140E
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n,Q=map(int,input().split())
xs,qs,tmp = [],[],set()
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x-0.5,t-x-0.5,x
    xs.append((s,1,x))
    xs.append((t,0,x))
    tmp.add(x)
xs.sort()
tmp = list(tmp)
tmp.sort()
x2i = dict()
for i, x in enumerate(tmp):
    x2i[x] = i

q = int(input())
rs = set()
st = SegTree([XN]*XN, XN, XN, min)
for t,r,x in xs:
    if q < t:
        c = st.query(0,XN)
        while True:
            if q < t:
                if c != XN:
                    print(tmp[c])
                else:
                    print(-1)
                Q-=1
                if Q == 0:
                    break
                q = int(input())
            else:
                break
#    print(t,r,x)
    if Q==0:
        break
    if r:
        st.update(x2i[x], x2i[x])
    else:
        st.update(x2i[x], XN)
print("-1\n"*Q)