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.

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let Q = buf_it.next().unwrap().parse::<usize>().unwrap();
    let STX = (0..N).map(|_| 
        (buf_it.next().unwrap().parse::<isize>().unwrap(),
         buf_it.next().unwrap().parse::<isize>().unwrap(),
         buf_it.next().unwrap().parse::<isize>().unwrap()
    )).collect::<Vec<_>>();
    let D = (0..Q).map(|_| buf_it.next().unwrap().parse::<isize>().unwrap()).collect::<Vec<_>>();

    let mut C = HashSet::new();
    for &d in &D{
        C.insert(-d);
    }
    for &(s,t,x) in &STX{
        C.insert(x-s+1);
        C.insert(x-t+1);
    }
    let mut C = C.iter().map(|&c| c).collect::<Vec<_>>();
    C.sort();
    let mut C2 = HashMap::new();
    for (i,&c) in C.iter().enumerate(){
        C2.insert(c,i);
    }

    let INF = 1_000_000_100;
    let mut T = SegmentTree::new(4*N,min,INF);
    for &(s,t,x) in &STX{
        T.set(*C2.get(&(x-t+1)).unwrap(),*C2.get(&(x-s+1)).unwrap(),x)
    }
    for &d in &D{
        let d = *C2.get(&(-d)).unwrap();
        let mut ans = T.get(d);
        if ans == INF {ans = -1;}
        println!("{}",ans);
    }
}

struct SegmentTree<N,F>
where F:Fn(N,N) ->N{
//モノイドが乗るセグ木(区間更新一点取得)
    n: usize,
    T: Vec<N>,
    func: F,
    identity: N,
}

impl<N:Copy,F> SegmentTree<N,F>
where F:Fn(N,N) ->N {
    fn new(n:usize,func:F,identity:N) -> SegmentTree<N,F>{
        let mut T = SegmentTree { n:n,T:Vec::new(),func:func,identity:identity};
        T.init();
        T
    }
    fn init(&mut self){
        self.n = 1<<format!("{:b}",self.n-1).len();
        self.T = (0..(2*self.n-1)).map(|_| self.identity).collect();
    }
    fn get(&mut self,index:usize) -> N{
        let i = index + self.n - 1;
        self._get(i)
    }
    fn _get(&mut self,i:usize) -> N{
        let n = self.T[i];
        if i==0{return n;}
        let m = self._get((i-1)/2);
        (self.func)(n,m)
    }
    fn set(&mut self,l:usize,r:usize,value:N){
        let n = self.n;
        self._set(l,r,value,0,0,n);
    }
    fn _set(&mut self,l:usize,r:usize,value:N,i:usize,a:usize,b:usize){
        if l==a && b==r{
            self.T[i] = value;
            return;
        }
        let j = (a+b)/2;
        if l<j{
            self._set(l,min(r,j),value,2*i+1,a,j);
        }
        if j<r{
            self._set(max(l,j),r,value,2*i+2,j,b);
        }
    }
}