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:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
            self.depth=n.bit_length()
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
        
        def lower_bound(self,x):
            sum_=0
            pos=0
            for i in range(self.depth,-1,-1):
                k=pos+(1<<i)
                if k<=self.num and sum_+self.dat[k]<x:
                    sum_+=self.dat[k]
                    pos+=1<<i
            return pos, sum_
    
    N,Q=map(int,input().split())
    S,T,X=[0]*N,[0]*N,[0]*N
    for i in range(N):
        S[i],T[i],X[i]=map(int,input().split())
    unique_X=sorted(list(set(X)))
    d={unique_X[i]:i for i,x in enumerate(unique_X)}
    l=[]
    for i in range(N):
        l.append((S[i]-X[i],1,d[X[i]]))
        l.append((T[i]-X[i],-1,d[X[i]]))
    l+=[(int(input()),2,0) for _ in range(Q)]
    l.sort()
    b=BIT(len(unique_X))
    c=0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,Q=map(int,input().split())
    l=[]
    for _ in range(N):
        S,T,X=map(int,input().split())
        l.append((S-X,T-X,X))
    l.sort(key=lambda t:(t[2],t[0]))
    D=[int(input()) for _ in range(Q)]
    prev=0
    for i in range(N):
        index=bisect_left(D,l[i][0])
        for j in range(prev,index):
            print(-1)
        prev=max(index,prev)
        index=bisect_left(D,l[i][1])
        for j in range(prev,index):
            print(l[i][2])
        prev=max(index,prev)
    for j in range(index,Q):
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,Q=map(int,input().split())
    l=[]
    for _ in range(N):
        S,T,X=map(int,input().split())
        l.append((S-X,T-X,X))
    l.sort(key=lambda t:t[2])
    D=[int(input()) for _ in range(Q)]
    prev=0
    for i in range(N):
        index=bisect_left(D,l[i][0])
        index=max(prev,index)
        for j in range(prev,index):
            print(-1)
        prev=index
        index=bisect_left(D,l[i][1])
        for j in range(prev,index):
            print(l[i][2])
        prev=index
    for j in range(index,Q):
        print(-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
events = []
for _ in range(N):
    S, T, X = map(int, input().split())
    events.append((S-X, X))
    events.append((T-X, -X))
events.sort(reverse=True)
ans = [0] * Q
cur = []
remove = set()
for i in range(Q):
    D = int(input())
    while events and events[-1][0] <= D:
        t, x = events.pop()
        if x > 0:
            heappush(cur, x)
        else:
            remove.add(-x)
    while cur and cur[0] in remove:
        remove.remove(cur[0])
        heappop(cur)
    ans[i] = cur[0] if cur else -1
print('\n'.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
events = []
for _ in range(N):
    S, T, X = map(int, input().split())
    events.append((S-X, X))
    events.append((T-X, -X))
events.sort()
events = deque(events)
ans = [0] * Q
cur = []
remove = set()
for i in range(Q):
    D = int(input())
    while events and events[0][0] <= D:
        t, x = events.popleft()
        if x > 0:
            heappush(cur, x)
        else:
            remove.add(-x)
    while cur and cur[0] in remove:
        remove.remove(cur[0])
        heappop(cur)
    ans[i] = cur[0] if cur else -1
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import heapq
N,Q=map(int,input().split())

event_list=[]
for i in range(N):
  S,T,X=map(int,input().split())
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(input())
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
hq=[]
for t,f,x in event_list:
  if f==1:
    heapq.heappush(hq,x)
  elif f==-1:
    heapq.heappop(hq)
  else:
    if len(hq)>0:
      answer_dic[t]=hq[0]
#print(answer_dic)

for d in dlist:
  if d in answer_dic:
    print(answer_dic[d])
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    from bisect import bisect_left
    from collections import namedtuple
    from operator import attrgetter
    import sys

    input = sys.stdin.readline
    Event = namedtuple('Event', 'pos start end')

    N, Q = map(int, input().split())

    events = []
    for _ in range(N):
        s, t, x = map(int, input().split())
        e = Event(pos=x, start=s - x, end=t - x)  # 時間[s-x,t-x)にpos=0にいるとpos=xで工事中
        events.append(e)
    events.sort(key=attrgetter('pos'))

    D = [int(input()) for _ in range(Q)]

    ans = [-1] * Q
    for e in events:
        left = bisect_left(D, e.start)
        right = bisect_left(D, e.end)
        # Dの要素で index が [left,right) 内のものは e.pos で工事中
        # e.pos 昇順ソートしているので, ans[idx] には工事中の最小のposが入る
        for idx in range(left, right):
            if ~ans[idx]:
                continue
            ans[idx] = x

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

import bisect
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
STX = [tuple(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x: x[2])
D = [int(input()) for i in range(Q)]

L = 0
ans = [-1]*Q
for s, t, x in STX:
    l = bisect.bisect_left(D, s-x)
    r = bisect.bisect_left(D, t-x)
    # print(l, r, L, s-x, t-x, x)
    # print(ans)
    if r - max(l, L) > 0:
        for i in range(max(l, L), r):
            ans[i] = x
    L = r


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

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappop,heappush
input = sys.stdin.readline
n,Q = map(int,input().split())
stx = [list(map(int,input().split())) for i in range(n)]
dls = [int(input()) for i in range(Q)]
event = []
for i in range(n):
  s,t,x = stx[i]
  event.append((s-x,1,x))
  event.append((t-x,-1,x))
for i in range(Q):
  d = dls[i]
  event.append((d,2,i))
event.sort()
"""
ans = [-1]*Q
s = set()
hq = []
for t,q,x in event:
  if q == 1:
    s.add(x)
    heappush(hq,x)
  elif q == -1:
    s.remove(x)
  elif q == 2:
    while hq and hq[0] not in s:
      heappop(hq)
    if hq:
      ans[x] = hq[0]
    else:
      ans[x] = -1
print(*ans,sep="\n")
"""

Submission status: Wrong Answer

Solution code:
import heapq
n,q=map(int,input().split())

event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append([s-x,1,x])
    event.append([t-x,-1,x])
event.sort()
d=[int(input()) for _ in range(q)]

k=0
stop=[]
for i in range(q):
    while k<2*n and event[k][0]<=d[i]:
        if event[k][1]==1: heapq.heappush(stop,event[k][2])
        else: stop.remove(event[k][2])
        k+=1
    print(stop[0] if stop!=[] else -1)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from bisect import bisect_left

n, q = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]

INF = 10 ** 9 + 1

time = []
for i, (s, t, x) in enumerate(stx):
    time.append([s - x, 0, i, x])
    time.append([t - x, 1, i, x])

time.sort()
xs = [-INF]
xxs = [-INF]
hp = []
heappush(hp, [INF, -1])
passed = set()
for xx, bl, i, x in time:
    xxs.append(xx)
    if bl:
        passed.add(i)

    else:
        heappush(hp, [x, i])

    while hp:
        mn, idx = heappop(hp)
        if idx not in passed:
            break
        if idx == -1:
            break

    xs.append(mn)
    heappush(hp, [mn, idx])

xs.append(INF)
for e in d:
    i = bisect_left(xxs, e)
    ans = xs[i]
    if ans == INF:
        ans = -1
    print(ans)

Submission status: Wrong Answer

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

class LazyPropSegmentTree:
    def __init__(self, a):
        self.padding = float('inf')        
        self.n = len(a)
        self.N = 1 << (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        self.lazy = [None] * (2*self.N - 1)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)>>1] = min(self.seg_data[i], self.seg_data[i-1])

    def indices_generator(self, i, j):
        # [i, j)
        # [idx1, idx2)を部分的に含むインデックスを降順にyieldするジェネレータ
        idx1 = self.N + i
        idx2 = self.N + j
        t = (j - i).bit_length()
        lm = (idx1 // (idx1 & -idx1)) >> 1
        rm = (idx2 // (idx2 & -idx2)) >> 1
        # while idx1 < idx2:
        for _ in range(t):
            if idx2 <= rm:
                yield idx2-1
            if idx1 <= lm:
                yield max(0, idx1-1)
            idx1 >>= 1
            idx2 >>= 1
        while idx1:
            yield idx1-1
            idx1 >>= 1
    
    def propagate(self, indices):
        # 遅延させていた値を伝搬させる
        # indicesは昇順
        for idx in indices:
            v = self.lazy[idx]
            if v is not None:
                idx1, idx2 = 2*idx + 1, 2*idx + 2
                self.lazy[idx1] = self.lazy[idx2] = v
                self.seg_data[idx1] = self.seg_data[idx2] = v
                self.lazy[idx] = None
        
    def update(self, i, j, x):
        # [i, j)の区間の値をxに変更する
        *should_prop, = self.indices_generator(i, j)
        self.propagate(should_prop[::-1])
        idx1 = self.N - 1 + i
        idx2 = self.N - 2 + j
        t = (j - i).bit_length()
        # while idx1 < idx2 + 1:
        for _ in range(t):
            if idx1&1 == 0: # idx1が偶数
                self.lazy[idx1] = self.seg_data[idx1] = x
            if idx2&1 == 1: # idx2が奇数
                self.lazy[idx2] = self.seg_data[idx2] = x
            idx1 >>= 1
            idx2 >>= 1
            idx2 -= 1        
        for idx in should_prop:
            idx1, idx2 = 2*idx + 1, 2*idx + 2
            self.seg_data[idx] = min(self.seg_data[idx1], self.seg_data[idx2])
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]


INF = float('inf')
N, Q = map(int, input().split())
STX = [list(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2], reverse=True)
st = LazyPropSegmentTree([INF]*Q)
d = [int(input()) for i in range(Q)]

for s, t, x in STX:
  il = bisect.bisect_left(d, s-x)
  ir = bisect.bisect_right(d, t-x-1)
  if il == ir:
    continue
  st.update(il, ir, x)

st.propagate([i for i in range(st.N-1)])
ans = [x if x<INF else -1 for x in st.data]
print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
import bisect

class LazyPropSegmentTree:
    def __init__(self, a):
        self.padding = float('inf')        
        self.n = len(a)
        self.N = 1 << (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        self.lazy = [None] * (2*self.N - 1)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)>>1] = min(self.seg_data[i], self.seg_data[i-1])
    
    def __len__(self):
        return self.n
    
    def enum_idx(self, idx1, idx2):
        # idx1とidx2を部分的に含むインデックス(=red)、完全に含むインデックス(=blue)を
        # 降順に出力
        red = []
        red_set = set()
        blue = []
        while idx1 < idx2:
            if idx2 &1 == 1: # idx2が奇数
                blue.append(idx2)
                idx2 >>= 1
                red.append(idx2)
                red_set.add(idx2)
                idx2 -= 1
            else:
                idx2 = (idx2 - 1) >> 1
            if idx1&1 == 0: # idx1が偶数
                blue.append(idx1)
                idx1 >>= 1
                red.append(idx1 - 1)
                red_set.add(idx1 - 1)
            else:
                idx1 >>= 1
        if idx1 not in red_set:
            blue.append(idx1)
        while idx1:
            idx1 = (idx1 - 1) >> 1
            red.append(idx1)
        return red, blue
    
    def propagate(self, indices):
        # 遅延させていた値を伝搬させる
        # indicesは昇順
        for idx in indices:
            v = self.lazy[idx]
            if v is not None:
                idx1, idx2 = 2*idx + 1, 2*idx + 2
                self.lazy[idx1] = self.lazy[idx2] = v
                self.seg_data[idx1] = self.seg_data[idx2] = v
                self.lazy[idx] = None
    
    def update(self, i, j, x):
        # [i, j)の区間の値をxに変更する
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        for idx in blue:
            self.lazy[idx] = self.seg_data[idx] = x
        
        for idx in red:
            idx1, idx2 = 2*idx + 1, 2*idx + 2
            self.seg_data[idx] = min(self.seg_data[idx1], self.seg_data[idx2])
    
    def query(self, i, j):
        # [i, j)
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        result = self.padding
        for idx in blue:
            result = min(result, self.seg_data[idx])
        return result
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]

N, Q = map(int, input().split())
STX = [list(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2], reverse=True)
st = LazyPropSegmentTree([float('inf')]*Q)
d = [int(input()) for i in range(Q)]

for s, t, x in STX:
  il = bisect.bisect_left(d, s-x)
  ir = bisect.bisect_right(d, t-x-1)
  if il == ir:
    continue
  st.update(il, ir, x)

for i in range(Q):
  x = st.query(i, i+1)
  if x < float('inf'):
    print(x)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import bisect

class LazyPropSegmentTree:
    def __init__(self, a):
        self.padding = float('inf')        
        self.n = len(a)
        self.N = 1 << (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        self.lazy = [None] * (2*self.N - 1)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)>>1] = min(self.seg_data[i], self.seg_data[i-1])
    
    def __len__(self):
        return self.n
    
    def enum_idx(self, idx1, idx2):
        # idx1とidx2を部分的に含むインデックス(=red)、完全に含むインデックス(=blue)を
        # 降順に出力
        red = []
        red_set = set()
        blue = []
        while idx1 < idx2:
            if idx2 &1 == 1: # idx2が奇数
                blue.append(idx2)
                idx2 >>= 1
                red.append(idx2)
                red_set.add(idx2)
                idx2 -= 1
            else:
                idx2 = (idx2 - 1) >> 1
            if idx1&1 == 0: # idx1が偶数
                blue.append(idx1)
                idx1 >>= 1
                red.append(idx1 - 1)
                red_set.add(idx1 - 1)
            else:
                idx1 >>= 1
        if idx1 not in red_set:
            blue.append(idx1)
        while idx1:
            idx1 = (idx1 - 1) >> 1
            red.append(idx1)
        return red, blue
    
    def propagate(self, indices):
        # 遅延させていた値を伝搬させる
        # indicesは昇順
        for idx in indices:
            v = self.lazy[idx]
            if v:
                idx1, idx2 = 2*idx + 1, 2*idx + 2
                self.lazy[idx1] = self.lazy[idx2] = v
                self.seg_data[idx1] = self.seg_data[idx2] = v
                self.lazy[idx] = None
    
    def update(self, i, j, x):
        # [i, j)の区間の値をxに変更する
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        for idx in blue:
            self.lazy[idx] = self.seg_data[idx] = x
        
        for idx in red:
            idx1, idx2 = 2*idx + 1, 2*idx + 2
            self.seg_data[idx] = min(self.seg_data[idx1], self.seg_data[idx2])
    
    def query(self, i, j):
        # [i, j)
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        result = self.padding
        for idx in blue:
            result = min(result, self.seg_data[idx])
        return result
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]

N, Q = map(int, input().split())
STX = [list(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2], reverse=True)
st = LazyPropSegmentTree([float('inf')]*Q)
d = [int(input()) for i in range(Q)]

for s, t, x in STX:
  il = bisect.bisect_left(d, s-x)
  ir = bisect.bisect_right(d, t-x-1)
  if il == ir:
    continue
  st.update(il, ir, x)

for i in range(Q):
  x = st.query(i, i+1)
  if x < float('inf'):
    print(x)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import bisect

class LazyPropSegmentTree:
    def __init__(self, a):
        self.padding = float('inf')        
        self.n = len(a)
        self.N = 1 << (self.n-1).bit_length()
        self.seg_data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-self.n)
        self.lazy = [None] * (2*self.N - 1)
        for i in range(2*self.N-2, 0, -2):
            self.seg_data[(i-1)>>1] = min(self.seg_data[i], self.seg_data[i-1])
    
    def __len__(self):
        return self.n
    
    def enum_idx(self, idx1, idx2):
        # idx1とidx2を部分的に含むインデックス(=red)、完全に含むインデックス(=blue)を
        # 降順に出力
        red = []
        red_set = set()
        blue = []
        while idx1 < idx2:
            if idx2 &1 == 1: # idx2が奇数
                blue.append(idx2)
                idx2 >>= 1
                red.append(idx2)
                red_set.add(idx2)
                idx2 -= 1
            else:
                idx2 = (idx2 - 1) >> 1
            if idx1&1 == 0: # idx1が偶数
                blue.append(idx1)
                idx1 >>= 1
                red.append(idx1 - 1)
                red_set.add(idx1 - 1)
            else:
                idx1 >>= 1
        if idx1 not in red_set:
            blue.append(idx1)
        while idx1:
            idx1 = (idx1 - 1) >> 1
            red.append(idx1)
        return red, blue
    
    def propagate(self, indices):
        # 遅延させていた値を伝搬させる
        # indicesは昇順
        for idx in indices:
            v = self.lazy[idx]
            if v:
                idx1, idx2 = 2*idx + 1, 2*idx + 2
                self.lazy[idx1] = self.lazy[idx2] = v
                self.seg_data[idx1] = self.seg_data[idx2] = v
                self.lazy[idx] = None
    
    def update(self, i, j, x):
        # [i, j)の区間の値をxに変更する
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        for idx in blue:
            self.lazy[idx] = self.seg_data[idx] = x
        
        for idx in red:
            idx1, idx2 = 2*idx + 1, 2*idx + 2
            self.seg_data[idx] = min(self.seg_data[idx1], self.seg_data[idx2])
    
    def query(self, i, j):
        # [i, j)
        red, blue = self.enum_idx(self.N-1+i, self.N-2+j)
        self.propagate(red[::-1])
        result = self.padding
        for idx in blue:
            result = min(result, self.seg_data[idx])
        return result
    
    @property
    def data(self):
        return self.seg_data[self.N-1:self.N-1+self.n]

N, Q = map(int, input().split())
STX = [list(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x:x[2], reverse=True)
st = LazyPropSegmentTree([float('inf')]*Q)
d = [int(input()) for i in range(Q)]

for s, t, x in STX:
  il = bisect.bisect_left(d, s-x)
  ir = bisect.bisect_right(d, t-x-1)
  st.update(il, ir, x)

for i in range(Q):
  x = st.query(i, i+1)
  if x < float('inf'):
    print(x)
  else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 0, x))
    EVENT.append((t-x, 1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = set()
for t, op, x in EVENT:
    if op == 2 and STOP:
        ans[x] = min(list(STOP))
    elif op == 0:
        #heapq.heappush(STOP, x)
        STOP.add(x)
    elif op == 1:
        if x in STOP:
            STOP.remove(x)
        # heapq.heapify(STOP)


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
STX = [[int(x) for x in input().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 0, x))
    EVENT.append((t-x, 1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

# print(EVENT)

STOP = []
for t, op, x in EVENT:
    if op == 2 and STOP:
        ans[x] = STOP[0]
    elif op == 0:
        heapq.heappush(STOP, x)
    elif op == 1:
        STOP.remove(x)


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
#STX = []
EVENT = []
for _ in range(N):
    s, t, x = map(int, input().split())
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, -1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

STOP = []
for t, op, x in EVENT:
    if op == 2 and STOP:
        ans[x] = STOP[0]
    elif op == 1:
        heapq.heappush(STOP, x)
    elif op == -1:
        STOP.remove(x)


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
#STX = []
EVENT = []
for _ in range(N):
    s, t, x = map(int, input().split())
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, -1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()

STOP = []
for t, op, x in EVENT:
    if op == 0 and STOP:
        ans[x] = STOP[0]
    elif op == 1:
        heapq.heappush(STOP, x)
    elif op == -1:
        STOP.remove(x)


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
#STX = []
EVENT = []
for _ in range(N):
    s, t, x = map(int, input().split())
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, -1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 0, i))

ans = [-1] * Q

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

STOP = []
for t, op, x in EVENT:
    if op == 0 and STOP:
        ans[x] = STOP[0]
    elif op == 1:
        heapq.heappush(STOP, x)
    elif op == -1:
        # STOP.remove(x)
        STOP = [i for i in STOP if not i == x]


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import bisect
import heapq
sys.setrecursionlimit(10 ** 7)

# TLE

N, Q = map(int, input().split())
#STX = []
EVENT = []
for _ in range(N):
    s, t, x = map(int, input().split())
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, -1, x))

for i in range(Q):
    d = int(input())
    EVENT.append((d, 0, i))

ans = [-1] * Q

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

STOP = []
for t, op, x in EVENT:
    if op == 0 and STOP:
        ans[x] = STOP[0]
    elif op == 1:
        heapq.heappush(STOP, x)
    elif op == -1:
        STOP.remove(x)


print("\n".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
STX = []
for _ in range(N):
    s, t, x = map(int, input().split())
    STX.append((s, t, x))

PEOPLE = []
for _ in range(Q):
    d = int(input())
    PEOPLE.append(d)

ans = [str(-1)] * Q

STX.sort(key=lambda x: x[2])

for s, t, x in STX:
    #print("s,t,x", s, t, x)
    i = np.searchsorted(PEOPLE, s - x)
    j = np.searchsorted(PEOPLE, t - x)
    #print("i,j", i, j)

    for k in range(i, j):
        if ans[k] == '-1':
            ans[k] = str(x)

    print(ans)

print("\n".join(ans))

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    s = S - X - 0.5
    t = T - X - 0.5
    queue.append((X, s, t))
    queue.append((-X, t, s))

for D in STXD[3 * N:]:
    queue.append((0, D, 0))

queue.sort(key=itemgetter(1), reverse=True)
heap = []
heapify(heap)
S, T, stop = 0, 0, -1
not_available = set()
while queue:
    x, s, t = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        s, t = t, s
        not_available.add((s, t, -x))
        if stop == -x:
            while heap:
                stop, s, t = heappop(heap)
                if (s, t, stop) not in not_available:
                    break
            else:
                stop = -1
    else:
        if stop != -1:
            if stop <= x:
                heappush(heap, (x, s, t))
            else:
                heappush(heap, (stop, S, T))
                S, T, stop = s, t, x
        else:
            S, T, stop = s, t, x

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    s = S - X - 0.5
    t = T - X - 0.5
    queue.append((s, t, X))
    queue.append((t, s, -X))

for D in STXD[3 * N:]:
    queue.append((D, 0, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
S, T, stop = 0, 0, -1
not_available = set()
while queue:
    s, t, x = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        s, t = t, s
        not_available.add((s, t, -x))
        if stop == -x:
            while heap:
                s, t, stop = heappop(heap)
                if (s, t, stop) not in not_available:
                    break
            else:
                stop = -1
    else:
        if stop != -1:
            if stop < x:
                heappush(heap, (s, t, x))
            else:
                heappush(heap, (S, T, stop))
                S, T, stop = s, t, x
        else:
            S, T, stop = s, t, x

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
from heapq import heapify, heappush, heappop

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    queue.append((S - X - 0.5, X))
    queue.append((T - X - 0.5, -X))

for D in STXD[3 * N:]:
    queue.append((D, 0))

queue.sort(key=itemgetter(0), reverse=True)
heap = []
heapify(heap)
stop = -1
not_available = set()
while queue:
    t, x = queue.pop()
    if x == 0:
        print(stop)
    elif x < 0:
        not_available.add(-x)
        if stop == -x:
            while heap:
                stop = heappop(heap)
                if stop not in not_available:
                    break
            else:
                stop = -1
    else:
        if stop != -1:
            stop, x = min(stop, x), max(stop, x)
            heappush(heap, x)
        else:
            stop = x

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = np.array(STXD[:3 * N], np.int64)
S = STX[::3]
T = STX[1::3]
X = STX[2::3]
arg = np.argsort(X)
X = X[arg]
S = S[arg]
T = T[arg]
D = np.array(STXD[3 * N:], np.int64)

s = S - X
t = T - X
STX = list(zip(s.tolist(), t.tolist(), X.tolist()))

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = STXD[:3 * N]
D = STXD[3 * N:]
queue = []

for S, T, X in zip(*[iter(STX)] * 3):
    S -= X
    T -= X
    queue.append((S, T, X))

queue.sort(key=itemgetter(2))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

read = sys.stdin.read

N, Q, *STXD = map(int, read().split())
STX = np.array(STXD[:3 * N], np.int64)
S = STX[::3]
T = STX[1::3]
X = STX[2::3]
arg = np.argsort(X)
X = X[arg]
S = S[arg]
T = T[arg]
D = np.array(STXD[3 * N:], np.int64)

s = S - X
t = T - X