Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]


class LinkedNode:
    def __init__(self, value, next=None):
        self.value = value
        self.next = next


ans = [-1 for _ in range(Q)]

last = LinkedNode(value=len(D) - 1)
unfixed = last
while unfixed.value > 0:
    unfixed = LinkedNode(value=unfixed.value - 1, next=unfixed)
# 最後から最初に戻れる
last.next = unfixed

prev = last
node = unfixed
for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    start_value = node.value
    while node.next.value != start_value and lo <= node.value < hi:
        prev = node
        node = node.next
    start_value = node.value
    while node.next.value != start_value and not lo <= node.value < hi:
        prev = node
        node = node.next

    node_exists = True
    while lo <= node.value < hi:
        ans[node.value] = x
        # 確定したので LinkedList から消す
        if node.value != node.next.value:
            prev.next = node.next
            node = node.next
        else:
            # 全部消えた
            node_exists = False
            break
    if not node_exists:
        break

for a in ans:
    print(int(a))


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

# (d, x, 0 or 1) のリスト
events = []

for xi, [s, t, x] in enumerate(STX):
    # [lo, hi) に出発した人は x で止まる
    lo = s - x
    hi = t - x
    events.append((lo, x, 1))  # 追加
    events.append((hi, x, 0))  # 削除

events.sort()
ev = 0
closes = set()
heap = []
for d in D:
    while ev < len(events) and events[ev][0] <= d:
        t, x, op = events[ev]
        if op == 1:
            closes.add(x)
            heapq.heappush(heap, x)
        else:
            closes.remove(x)
        ev += 1
    while heap and heap[0] not in closes:
        heapq.heappop(heap)
    if heap:
        print(heap[0])
    else:
        print(-1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

# (d, x, 0 or 1) のリスト
events = []

for xi, [s, t, x] in enumerate(STX):
    # [lo, hi) に出発した人は x で止まる
    lo = s - x
    hi = t - x
    events.append((lo, x, 1))  # 追加
    events.append((hi, x, 0))  # 削除

events.sort()
ev = 0
closes = set()
for d in D:
    while ev < len(events) and events[ev][0] <= d:
        t, x, op = events[ev]
        if op == 1:
            closes.add(x)
        else:
            closes.remove(x)
        ev += 1
    if closes:
        print(min(closes))
    else:
        print(-1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Runtime Error):
import bisect
import heapq
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

# (d, x, x のインデックス) のリスト
lows = []
highs = []

for xi, [s, t, x] in enumerate(STX):
    # [lo, hi) に出発した人は x で止まる
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    lows.append((D[lo], x, xi))
    highs.append((D[hi], x, xi))

lows.sort()
highs.sort()
L = 0
r = 0
# (x, D のインデックス)
heap = []
used = [False for _ in range(len(lows))]

for i, d in enumerate(D):
    while L < len(lows) and lows[L][0] <= d:
        heapq.heappush(heap, (lows[L][1], lows[L][2]))
        L += 1
    while r < len(highs) and highs[r][0] <= d:
        used[highs[r][2]] = True
        r += 1
    while heap and used[heap[0][1]]:
        heapq.heappop(heap)
    if heap:
        print(heap[0][0])
    else:
        print(-1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Runtime Error):
import bisect
import heapq
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]

# (d, x, x のインデックス) のリスト
lows = []
highs = []

for xi, [s, t, x] in enumerate(STX):
    # [lo, hi) に出発した人は x で止まる
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    lows.append((D[lo], x, xi))
    highs.append((D[hi], x, xi))

lows.sort()
highs.sort()
L = 0
r = 0
# (x, D のインデックス)
heap = []
used = set()

for i, d in enumerate(D):
    while L < len(lows) and lows[L][0] <= d:
        heapq.heappush(heap, (lows[L][1], lows[L][2]))
        L += 1
    while r < len(highs) and highs[r][0] <= d:
        used.add(highs[r][2])
        r += 1
    while heap and heap[0][1] in used:
        heapq.heappop(heap)
    if heap:
        print(heap[0][0])
    else:
        print(-1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Runtime Error):
import bisect
import heapq
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = np.array([int(input()) for _ in range(Q)])

# (d, x, x のインデックス) のリスト
lows = []
highs = []

for xi, [s, t, x] in enumerate(STX):
    # [lo, hi) に出発した人は x で止まる
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    lows.append((D[lo], x, xi))
    highs.append((D[hi], x, xi))

lows.sort()
highs.sort()
L = 0
r = 0
# (x, D のインデックス)
heap = []
used = set()

for i, d in enumerate(D):
    while L < len(lows) and lows[L][0] <= d:
        heapq.heappush(heap, (lows[L][1], lows[L][2]))
        L += 1
    while r < len(highs) and highs[r][0] <= d:
        used.add(highs[r][2])
        r += 1
    while heap and heap[0][1] in used:
        heapq.heappop(heap)
    if heap:
        print(heap[0][0])
    else:
        print(-1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')
N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = np.array([int(next(sys.stdin)) for _ in range(Q)])

ans = np.full(Q, np.inf)

for s, t, x in STX:
    # [lo, hi) に出発した人は x で止まる
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    ans[lo:hi] = np.minimum(x, ans[lo:hi])

for a in ans:
    print(int(a) if a < np.inf else -1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')
MAXINT = sys.maxsize

N, Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = np.array([int(input()) for _ in range(Q)])

ans = np.full(Q, np.inf)

for s, t, x in sorted(STX, key=lambda stx: -stx[2]):
    # [lo, hi) に出発した人は x で止まる
    lo = bisect.bisect_left(D, s - x)
    hi = bisect.bisect_left(D, t - x)
    ans[lo:hi] = x

for a in ans:
    print(int(a) if a < np.inf else -1)


Fixed submission:
import bisect
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N, Q = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]

ans = [-1 for _ in range(Q)]
nexts = [-1 for _ in range(Q)]

for s, t, x in sorted(STX, key=lambda stx: (stx[2], stx[1])):
    # [lo, hi) に出発した人は x で止まる
    # x の小さい順にソート済みなのでここで確定
    lo = max(0, bisect.bisect_left(D, s - x))
    hi = min(len(D), bisect.bisect_left(D, t - x))

    p = lo
    while p < hi:
        if nexts[p] == -1:
            ans[p] = x
            nexts[p] = hi
            p += 1
        else:
            prev = p
            p = nexts[p]
            nexts[prev] = hi

for a in ans:
    print(int(a))