Problem:


Score : 500 points

Problem Statement

There is an infinitely long street that runs west to east, which we consider as a number line.

There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.

Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.

Find the distance each of the Q people will walk.

Constraints

All values in input are integers.

1 \leq N, Q \leq 2 \times 10^5

0 \leq S_i < T_i \leq 10^9

1 \leq X_i \leq 10^9

0 \leq D_1 < D_2 < ... < D_Q \leq 10^9

If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

Input

Input is given from Standard Input in the following format:

N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

Output

Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

Sample Input 1

4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

Sample Output 1

2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.

The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.

The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.



Sample input:
4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8


Sample output:
2
2
10
-1
13
-1

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, p = LI()
    print((a*3+p)//2)
    return

#B
def B():
    n = II()
    sp = []
    for i in range(n):
        sp.append(input().split())
    another = [(s[0], -1 * int(s[1]),num) for num,s in enumerate(sp)]
    another.sort()
    for s,p,q in another:
        print(q+1)

    return

#C
def C():
    n, m = LI()
    ks = LIR_(m)
    p = LI()
    patern = itertools.product(range(2), repeat=n)
    ans = 0
    for on in patern:
        ki = [0 for i in range(m)]
        for num, oni in enumerate(on):
            if oni:
                for i,ksi in enumerate(ks):
                    ksi = ksi[1::]
                    if num in ksi:
                        ki[i] ^= 1
        for num, pi in enumerate(p):
            if pi != ki[num]:
                break
        else:
            ans += 1
    print(ans)

            
    return

#D
def D():
    N, K = LI()#random.randint(1,50),random.randint(1,100)
    v = LI()#[random.randint(-10 ** 2, 10 ** 2) for i in range(N)]
    ans = 0
    for a in range(min(N, K) + 1):
        for b in range(min(N, K) + 1):
            if a + b > min(K,N):
                break
            if a == b == 0:
                continue
            deletes = K - a - b
            left = v[:a]
            right = v[:-b-1:-1]
            x = left + right
            x.sort()
            tmp = sum(x)
            for delete in range(min(deletes, len(x))):
                if x[delete] >= 0:
                    break
                tmp -= x[delete]
            ans = max(ans,tmp)
    
    print(ans)
                

    return


#E
def E():  
    N,q = LI()
    STX = LIR(N)
    D = IR(q)
    LV = q.bit_length()
    N0 = 1 << LV

    data = [inf] * (N0 << 1)
    INF = inf

    def update(l, r, x):
    
        #  区間[l, r)のdataの値を更新
        L = N0 + l; R = N0 + r
        while L < R:
            if R & 1:
                R -= 1
                data[R] = min(data[R], x)
            if L & 1:
                data[L] = min(data[L], x)
                L += 1
            L >>= 1; R >>= 1

    def query(l, r):
        L = N0 + l; R = N0 + r
        #  区間[l, r)の最小値を求める
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, data[R])
            if L & 1:
                s = min(s, data[L])
                L += 1
            L >>= 1; R >>= 1
        return s

    for s, t, x in STX:
        XS = max(0, s - x)
        XT = max(0, t - x)
        XS_index = bisect_left(D, XS)
        XT_index = bisect_left(D, XT)
        if XS_index == XT_index:
            continue
        update(XS_index, XT_index, x)

    for i in range(q):
        a = query(i, i + 1)
        print(a if a != inf else -1)
#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, p = LI()
    print((a*3+p)//2)
    return

#B
def B():
    n = II()
    sp = []
    for i in range(n):
        sp.append(input().split())
    another = [(s[0], -1 * int(s[1]),num) for num,s in enumerate(sp)]
    another.sort()
    for s,p,q in another:
        print(q+1)

    return

#C
def C():
    n, m = LI()
    ks = LIR_(m)
    p = LI()
    patern = itertools.product(range(2), repeat=n)
    ans = 0
    for on in patern:
        ki = [0 for i in range(m)]
        for num, oni in enumerate(on):
            if oni:
                for i,ksi in enumerate(ks):
                    ksi = ksi[1::]
                    if num in ksi:
                        ki[i] ^= 1
        for num, pi in enumerate(p):
            if pi != ki[num]:
                break
        else:
            ans += 1
    print(ans)

            
    return

#D
def D():
    N, K = LI()#random.randint(1,50),random.randint(1,100)
    v = LI()#[random.randint(-10 ** 2, 10 ** 2) for i in range(N)]
    ans = 0
    for a in range(min(N, K) + 1):
        for b in range(min(N, K) + 1):
            if a + b > min(K,N):
                break
            if a == b == 0:
                continue
            deletes = K - a - b
            left = v[:a]
            right = v[:-b-1:-1]
            x = left + right
            x.sort()
            tmp = sum(x)
            for delete in range(min(deletes, len(x))):
                if x[delete] >= 0:
                    break
                tmp -= x[delete]
            ans = max(ans,tmp)
    
    print(ans)
                

    return


#E
def E():  
    N,q = LI()
    STX = LIR(N)
    D = IR(q)
    LV = q.bit_length()
    N0 = 1 << LV
    data = [inf] * (N0 << 1)
    lazy = [None] * (N0 << 1)
    INF = inf

    # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
    def gindex(l, r):
        L = (l + N0) >> 1; R = (r + N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>= 1

    # 1-indexedで単調増加のインデックスリストを渡す
    def propagates(*ids):
        for i in reversed(ids):
            v = lazy[i-1]
            if v is None:
                continue
            lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
            lazy[i-1] = None
        return
    
    def update(l, r, x):
        *ids, = gindex(l, r)
        # 1. トップダウンにlazyの値を伝搬
        propagates(*ids)
    
        # 2. 区間[l, r)のdata, lazyの値を更新
        L = N0 + l; R = N0 + r
        while L < R:
            if R & 1:
                R -= 1
                lazy[R-1] = data[R-1] = min(data[R-1], x)
            if L & 1:
                lazy[L-1] = data[L-1] = min(data[L-1], x)
                L += 1
            L >>= 1; R >>= 1

        # 3. 伝搬させた区間について、ボトムアップにdataの値を伝搬する
        for i in ids:
            data[i - 1] = min(data[2 * i - 1], data[2 * i])
    
    def query(l, r):
        # 1. トップダウンにlazyの値を伝搬
        propagates(*gindex(l, r))
        L = N0 + l; R = N0 + r

        # 2. 区間[l, r)の最小値を求める
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, data[R-1])
            if L & 1:
                s = min(s, data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

    for s, t, x in STX:
        XS = max(0, s - x)
        XT = max(0, t - x)
        XS_index = bisect_left(D, XS)
        XT_index = bisect_left(D, XT)
        if XS_index == XT_index:
            continue
        update(XS_index, XT_index, x)

    for i in range(q):
        a = query(i, i + 1)
        print(a if a != inf else -1)
#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, p = LI()
    print((a*3+p)//2)
    return

#B
def B():
    n = II()
    sp = []
    for i in range(n):
        sp.append(input().split())
    another = [(s[0], -1 * int(s[1]),num) for num,s in enumerate(sp)]
    another.sort()
    for s,p,q in another:
        print(q+1)

    return

#C
def C():
    n, m = LI()
    ks = LIR_(m)
    p = LI()
    patern = itertools.product(range(2), repeat=n)
    ans = 0
    for on in patern:
        ki = [0 for i in range(m)]
        for num, oni in enumerate(on):
            if oni:
                for i,ksi in enumerate(ks):
                    ksi = ksi[1::]
                    if num in ksi:
                        ki[i] ^= 1
        for num, pi in enumerate(p):
            if pi != ki[num]:
                break
        else:
            ans += 1
    print(ans)

            
    return

#D
def D():
    N, K = LI()#random.randint(1,50),random.randint(1,100)
    v = LI()#[random.randint(-10 ** 2, 10 ** 2) for i in range(N)]
    ans = 0
    for a in range(min(N, K) + 1):
        for b in range(min(N, K) + 1):
            if a + b > min(K,N):
                break
            if a == b == 0:
                continue
            deletes = K - a - b
            left = v[:a]
            right = v[:-b-1:-1]
            x = left + right
            x.sort()
            tmp = sum(x)
            for delete in range(min(deletes, len(x))):
                if x[delete] >= 0:
                    break
                tmp -= x[delete]
            ans = max(ans,tmp)
    
    print(ans)
                

    return


#E
def E():  
    N,q = LI()
    STX = LIR(N)
    D = IR(q)
    LV = (q - 1).bit_length()
    N0 = 1 << LV
    data = [inf] * (N0 << 1)
    lazy = [None] * (N0 << 1)
    INF = inf

    # 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
    def gindex(l, r):
        L = (l + N0) >> 1; R = (r + N0) >> 1
        lc = 0 if l & 1 else (L & -L).bit_length()
        rc = 0 if r & 1 else (R & -R).bit_length()
        for i in range(LV):
            if rc <= i:
                yield R
            if L < R and lc <= i:
                yield L
            L >>= 1; R >>= 1

    # 1-indexedで単調増加のインデックスリストを渡す
    def propagates(*ids):
        for i in reversed(ids):
            v = lazy[i-1]
            if v is None:
                continue
            lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
            lazy[i-1] = None
        return
    
    def update(l, r, x):
        *ids, = gindex(l, r)
        # 1. トップダウンにlazyの値を伝搬
        propagates(*ids)
    
        # 2. 区間[l, r)のdata, lazyの値を更新
        L = N0 + l; R = N0 + r
        while L < R:
            if R & 1:
                R -= 1
                lazy[R-1] = data[R-1] = min(data[R-1], x)
            if L & 1:
                lazy[L-1] = data[L-1] = min(data[L-1], x)
                L += 1
            L >>= 1; R >>= 1

        # 3. 伝搬させた区間について、ボトムアップにdataの値を伝搬する
        for i in ids:
            data[i - 1] = min(data[2 * i - 1], data[2 * i])
    
    def query(l, r):
        # 1. トップダウンにlazyの値を伝搬
        propagates(*gindex(l, r))
        L = N0 + l; R = N0 + r

        # 2. 区間[l, r)の最小値を求める
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, data[R-1])
            if L & 1:
                s = min(s, data[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

    for s, t, x in STX:
        XS = max(0, s - x)
        XT = max(0, t - x)
        XS_index = bisect_left(D, XS)
        XT_index = bisect_left(D, XT)
        if XS_index == XT_index:
            continue
        update(XS_index, XT_index, x)

    for i in range(q):
        a = query(i, i + 1)
        print(a if a != inf else -1)
#F
def F():
    return

#Solve
if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import heapq
n,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
d=[int(input()) for i in range(q)]
L1=[]
for i in range(n):
  L1.append([l[i][0]-l[i][2],1,l[i][2]])
  L1.append([l[i][1]-l[i][2],-1,l[i][2]])
L1.sort()
L2=[]
heapq.heapify(L2)
L3=[]
L3=set(L2)
ctd=0
for i in range(len(L1)):
  if ctd<q:
    while L1[i][0]>d[ctd]:
      if len(L2)!=0:
        print(heapq.heappop(L2))
      else:
        print(-1)
      ctd+=1
      if ctd==q:
        break
  else:
    break
  if L1[i][1]==1:
    heapq.heappush(L2,L1[i][2])
    L3.add(L1[i][2])
  else:
    L3.remove(L1[i][2])
while ctd<q:
  print(-1)
  ctd+=1

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
import heapq
inpl = lambda: list(map(int,input().split()))

N, Q = inpl()
STX = [inpl() for _ in range(N)]
D = [int(input()) for _ in range(Q)]
event = []
for s, t, x in STX:
    event.append((s-x,1,x))
    event.append((t-x,0,x))
event.sort()

INF = 10**10
T = []
X = [INF]
xq = []
for t, e, x in event:
    if e == 1:
        if x < X[-1]:
            heapq.heappush(xq,(X[-1],1))
            T.append(t)
            X.append(x)
        else:
            heapq.heappush(xq,(x,1))
    else:
        if x == X[-1]:
            x, e = heapq.heappop(xq)
            while e == 0:
                heapq.heappop(xq)
                x, e = heapq.heappop(xq)
            T.append(t)
            X.append(x)
        else:
            heapq.heappush(xq,(x,0))

for d in D:
    x = X[bisect_right(T,d)]
    if x >= INF:
        print(-1)
    else:
        print(x)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right
import heapq
inpl = lambda: list(map(int,input().split()))

N, Q = inpl()
STX = [inpl() for _ in range(N)]
D = [int(input()) for _ in range(Q)]
event = []
for s, t, x in STX:
    event.append((s-x,1,x))
    event.append((t-x,0,x))
event.sort()

INF = 10**10
T = []
X = [INF]
minx = INF
xq = [(INF,1)]
for t, e, x in event:
    if e == 1:
        if x < minx:
            heapq.heappush(xq,(minx,1))
            minx = x
            T.append(t)
            X.append(x)
        else:
            heapq.heappush(xq,(x,1))
    else:
        if x == minx:
            x, e = heapq.heappop(xq)
            while e == 0:
                heapq.heappop(xq)
                x, e = heapq.heappop(xq)
            minx = x
            T.append(t)
            X.append(x)
        else:
            heapq.heappush(xq,(x,0))

for d in D:
    x = X[bisect_right(T,d)]
    if x >= INF:
        print(-1)
    else:
        print(x)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main():
    N, Q, *I = map(int, open(0).read().split())
    STX, D = I[:3 * N], I[3 * N:]

    E = sorted(zip(*[iter(STX)] * 3), key=lambda x: x[1])

    R = [-1] * Q
    ans = [-1] * Q

    for s, t, x in E:
        l = bisect_left(D, s - x)
        r = bisect_left(D, t - x)
        while l < r:
            if R[l] == -1:
                ans[l] = x
                R[l] = r
                l += 1
            else:
                l = R[l]

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
lst = [[] for _ in range(q+1)]
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    lst[l].append(x)
    lst[r-1].append(x)
for i in lst[:-1]:
    if len(i) == 0:
        print(-1)
    else:
        print(i[0])

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N, Q = LI()
stx = [LI() for _ in range(N)]
OUT = []
for i in range(N):
    e = max(0,stx[i][1]-stx[i][2])
    s = max(0,stx[i][0]-stx[i][2])
    OUT.append([s,e,stx[i][2]])

OUT.sort(key=lambda x: x[1])
#print(OUT)
k = int(0)
for i in range(Q):
    D = I()
    if k<N:
        while k<N-1 and D>=OUT[k][1]:
            k +=1
        if D>=OUT[k][0]and D<OUT[k][1]:
            print(OUT[k][2])
        else:
            print("-1")
    else:
        print("-1")

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N, Q = LI()
stx = [LI() for _ in range(N)]
OUT = []
for i in range(N):
    e = max(0,stx[i][1]-stx[i][2])
    s = max(0,stx[i][0]-stx[i][2])
    OUT.append([s,e,stx[i][2]])

OUT.sort(key=lambda x: x[1])
#print(OUT)
k = int(0)
for i in range(Q):
    D = I()
    if k<N:
        while k<N-1 and D>=OUT[k][1]:
            k +=1
        if D>=OUT[k][0]:
            print(OUT[k][2])
        else:
            print("-1")
    else:
        print("-1")

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N, Q = LI()
stx = [LI() for _ in range(N)]
OUT = []
for i in range(N):
    e = max(0,stx[i][1]-stx[i][2])
    s = max(0,stx[i][0]-stx[i][2])
    OUT.append([s,e,stx[i][2]])

OUT.sort(key=lambda x: x[1])
#print(OUT)
k = int(0)
for i in range(Q):
    D = I()
    if k<N:
        while k<N and D>=OUT[k][1]:
            k +=1
        if k<N and D>=OUT[k][0]:
            print(OUT[k][2])
        else:
            print("-1")
    else:
        print("-1")

Submission status: Wrong Answer

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

N, Q = LI()
stx = [LI() for _ in range(N)]
cou = int(0)
d = int(0)
OUT = []
for i in range(N):
    e = max(0,stx[i][1]-stx[i][2])
    s = max(0,stx[i][0]-stx[i][2])
    OUT.append([s,e,stx[i][2]])

OUT.sort(key=lambda x: x[1])
#print(OUT)
k = int(0)
for i in range(Q):
    D = int(input())
    while k<N and D>=OUT[k][1]:
        k +=1

    if k<N and D>=OUT[k][0]:
        print(OUT[k][2])
        cou = 1
    else:
        print("-1")
        cou = -1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*q
print(stx,d)
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    for j in range(l,r):
        if ans[j] == -1:
            ans[j] = x
            break
    #print(l,r)
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
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 

if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,input().split())
        xs += [(s-x,0,x,i), (t-x,1,x,i)]
    xs.sort()
    xs+=[(mx,0,x,i+1)]
    ys = set()
    q = int(input())
    for x in xs:
        if q < x[0]:
            mm = segl[0] if segl[0]!= mx else -1
            ys = set()
            while True:
                if q < x[0]:
                    print(mm)
                    Q-=1
                    if Q==0:
                        sys.exit()
                    q = int(input())
                    continue
                break
        segl[x[3]+b_num-1] = mx if x[1] else x[2]
        ys.add((x[3]+b_num-2)//2)

Submission status: Wrong Answer

Solution code:
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 

if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,input().split())
        xs += [(s-x,0,x,i), (t-x,1,x,i)]
    xs.sort()
    xs+=[(mx,0,x,i+1)]
    ys = set()
    q = int(input())
    for x in xs:
        if q < x[0]:
            for _ in range(bn):
                nys = set()
                for k in ys:
                    segl[k] = min(segl[k*2+1],segl[k*2+2])
                    nys.add((k-1)//2)
                ys = nys
            mm = segl[0] if segl[0]!= mx else -1
            ys = set()
            while True:
                if q < x[0]:
                    print(mm)
                    Q-=1
                    if Q==0:
                        sys.exit()
                    q = int(input())
                break
        segl[x[3]+b_num-1] = mx if x[1] else x[2]
        ys.add((x[3]+b_num-2)//2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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:
        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)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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]

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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:
        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]

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

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

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)

Submission status: Wrong Answer

Solution code:
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)]
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)

Submission status: Wrong Answer

Solution code:
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 i in range(n):
    s,t,x=map(int,input().split())
    xs += [(s-x-0.5,0,x,i), (t-x-0.4,1,x,i)]
for _ in range(Q):
    xs.append((int(input()),2,0,0))
xs.sort(key=lambda x :x[0])
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)

Submission status: Wrong Answer

Solution code:
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 i in range(n):
    s,t,x=map(int,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)

Submission status: Wrong Answer

Solution code:
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 

if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=map(int,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)

Submission status: Wrong Answer

Solution code:
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs,qs = [],[]
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x,t-x,x
    xs += [(s,1,x), (t,0,x)]
for _ in range(Q):
    qs.append(int(input()))

xs.sort(key=lambda x:x[0])

Submission status: Wrong Answer

Solution code:
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs,qs = [],[]
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x,t-x,x
    xs += [(s,1,x), (t,0,x)]
for _ in range(Q):
    qs.append(int(input()))

xs.sort()

Submission status: Wrong Answer

Solution code:
import sys
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=map(int,input().split())
xs,qs = [],[]
for _ in range(n):
    s,t,x=map(int,input().split())
    s,t,x=s-x,t-x,x
    xs += [(s,1,x), (t,0,x)]
for _ in range(Q):
    qs.append(int(input()))

xs.sort()

h=set()
qi = 0
q = qs[qi]
for t,r,x in xs:
    if q < t:
        if h:
            c = -1
        else:
            c = -1
        while True:
            if q < t:
                print(c)
                Q-=1
                if Q:
                    qi += 1
                    q = qs[qi]
                    continue
                sys.exit()
            break
print("-1\n"*Q)