Language: C++

package main

import (
	"fmt"
	"sort"
)

type Comparable interface {
	less(Comparable) bool
}

type Node struct {
	elem             Comparable
	par, left, right *Node
}

func NewNode(elem Comparable, par *Node) *Node {
	node := new(Node)
	node.elem = elem
	node.par = par
	return node
}

func (node *Node) insert(elem Comparable, par *Node) bool {
	// fmt.Println("Node::insert is called")
	if node == nil {
		node = NewNode(elem, par)
		if par != nil {
			if par.elem.less(elem) {
				par.right = node
			} else {
				par.left = node
			}
		}
		return true
	}
	if node.elem.less(elem) {
		return node.right.insert(elem, node)
	} else if elem.less(node.elem) {
		return node.left.insert(elem, node)
	} else {
		return false
	}
}

func (node *Node) find(elem Comparable) *Node {
	// fmt.Println("Node::find is called")
	if node == nil {
		return nil
	}
	if node.elem.less(elem) {
		return node.right.find(elem)
	} else if elem.less(node.elem) {
		return node.left.find(elem)
	} else {
		return node
	}
}

func (node *Node) getMin() *Node {
	// fmt.Println("Node::getMin is called")
	if node.left == nil {
		return node
	} else {
		return node.left.getMin()
	}
}

func (node *Node) getMax() *Node {
	// fmt.Println("Node::getMax is called")
	if node.right == nil {
		return node
	} else {
		return node.right.getMax()
	}
}

func (node *Node) replace() {
	// fmt.Println("Node::replace is called")
	var child *Node
	if node.left == nil {
		child = node.right
	} else {
		child = node.left
	}

	if child != nil {
		child.par = node.par
	}

	if node.par != nil {
		if node.par.elem.less(node.elem) {
			node.par.right = child
		} else {
			node.par.left = child
		}
	}
}

func (node *Node) erase() {
	// fmt.Println("Node::erase is called")
	if node == nil {
		return
	}

	if node.left != nil && node.right != nil {
		rightMinNode := node.right.getMin()
		node.elem, rightMinNode.elem = rightMinNode.elem, node.elem
		rightMinNode.erase()
	} else {
		node.replace()
	}
}

func (node *Node) next() *Node {
	if node.right != nil {
		return node.right.getMin()
	} else {
		n := node
		for {
			if n.par == nil {
				return nil
			}
			if n.elem.less(n.par.elem) {
				return n.par
			}
			n = n.par
		}
	}
}

func (node *Node) show() {
	if node == nil {
		return
	}
	node.left.show()
	fmt.Println(node.elem)
	node.right.show()
}

type Set struct {
	size uint
	root *Node
}

func (set *Set) insert(elem Comparable) {
	// fmt.Println("Set::insert is called")
	if set.root == nil {
		set.root = NewNode(elem, nil)
		set.size++
	} else {
		if set.root.insert(elem, nil) {
			set.size++
		}
	}
}

func (set *Set) find(elem Comparable) *Node {
	// fmt.Println("Set::find is called")
	return set.root.find(elem)
}

func (set *Set) erase(elem Comparable) {
	// fmt.Println("Set::erase is called")
	node := set.root.find(elem)
	if node == nil {
		return
	}
	if node == set.root {
		set.root = nil
	} else {
		node.erase()
	}
	set.size--
}

func (set *Set) begin() *Node {
	return set.root.getMin()
}

func (set *Set) show() {
	set.root.show()
}

type Int int64

func (item Int) less(other Comparable) bool {
	otherT, ok := other.(Int)
	if !ok {
		//handle error (other was not of type T)
	}
	return item < otherT
}

var N, Q int
var s, t, x, d []int64

type Event struct{ id, tp int }
type Events []Event

func (Event Events) Len() int { return len(Event) }
func (Event Events) Less(i, j int) bool {
	var l, r int64
	if Event[i].tp == 0 {
		l = s[Event[i].id]
	} else {
		l = t[Event[i].id]
	}
	if Event[j].tp == 0 {
		r = s[Event[j].id]
	} else {
		r = t[Event[j].id]
	}
	if l == r {
		return Event[i].tp > Event[j].tp
	} else {
		return l < r
	}
}
func (Event Events) Swap(i, j int) { Event[i], Event[j] = Event[j], Event[i] }

var ord Events

func main() {
	fmt.Scan(&N, &Q)

	s = make([]int64, N)
	t = make([]int64, N)
	x = make([]int64, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&s[i], &t[i], &x[i])
		s[i] -= x[i]
		t[i] -= x[i]
	}

	d := make([]int64, Q)
	for i := 0; i < Q; i++ {
		fmt.Scan(&d[i])
	}

	ord := make(Events, 2*N)
	for i := 0; i < N; i++ {
		ord[2*i] = Event{id: i, tp: 0}
		ord[2*i+1] = Event{id: i, tp: 1}
	}

	sort.Sort(ord)

	set := new(Set)
	set.insert(Int(1 << 60))

	j := 0
	ans := make([]Int, Q)

	for i := 0; i < Q; i++ {
		for ; j < 2*N; j++ {
			id := ord[j].id
			tp := ord[j].tp
			var z int64
			if tp == 0 {
				z = s[id]
			} else {
				z = t[id]
			}

			if d[i] < z {
				break
			}

			if tp == 0 {
				set.insert(Int(x[id]))
			} else {
				set.erase(Int(x[id]))
			}
		}

		ans[i] = set.begin().elem.(Int)
	}

	for i := 0; i < Q; i++ {
		if ans[i] == 1<<60 {
			fmt.Println(-1)
		} else {
			fmt.Println(ans[i])
		}
	}
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:12:1: error: 'type' does not name a type; did you mean 'typeof'?
   12 | type Node struct {
      | ^~~~
      | typeof
a.cc:17:1: error: 'func' does not name a type
   17 | func NewNode(elem Comparable, par *Node) *Node {
      | ^~~~
a.cc:24:6: error: expected constructor, destructor, or type conversion before '(' token
   24 | func (node *Node) insert(elem Comparable, par *Node) bool {
      |      ^
a.cc:46:6: error: expected constructor, destructor, or type conversion before '(' token
   46 | func (node *Node) find(elem Comparable) *Node {
      |      ^
a.cc:60:6: error: expected constructor, destructor, or type conversion before '(' token
   60 | func (node *Node) getMin() *Node {
      |      ^
a.cc:69:6: error: expected constructor, destructor, or type conversion before '(' token
   69 | func (node *Node) getMax() *Node {
      |      ^
a.cc:78:6: error: expected constructor, destructor, or type conversion before '(' token
   78 | func (node *Node) replace() {
      |      ^
a.cc:100:6: error: expected constructor, destructor, or type conversion before '(' token
  100 | func (node *Node) erase() {
      |      ^
a.cc:115:6: error: expected constructor, destructor, or type conversion before '(' token
  115 | func (node *Node) next() *Node {
      |      ^
a.cc:132:6: error: expected constructor, destructor, or type conversion before '(' token
  132 | func (node *Node) show() {
      |      ^
a.cc:141:1: error: 'type' does not name a type; did you mean 'typeof'?
  141 | type Set struct {
      | ^~~~
      | typeof
a.cc:146:6: error: expected constructor, destructor, or type conversion before '(' token
  146 | func (set *Set) insert(elem Comparable) {
      |      ^
a.cc:158:6: error: expected constructor, destructor, or type conversion before '(' token
  158 | func (set *Set) find(elem Comparable) *Node {
      |      ^
a.cc:163:6: error: expected constructor, destructor, or type conversion before '(' token
  163 | func (set *Set) erase(elem Comparable) {
      |      ^
a.cc:177:6: error: expected constructor, destructor, or type conversion before '(' token
  177 | func (set *Set) begin() *Node {
      |      ^
a.cc:181:6: error: expected constructor, destructor, or type conversion before '(' token
  181 | func (set *Set) show() {
      |      ^
a.cc:185:1: error: 'type' does not name a type; did you mean 'typeof'?
  185 | type Int int64
      | ^~~~
      | typeof
a.cc:195:1: error: 'var' does not name a type
  195 | var N, Q int
      | ^~~
a.cc:199:1: error: 'type' does not name a type; did you mean 'typeof'?
  199 | type Events []Event
      | ^~~~
      | typeof
a.cc:202:6: error: expected constructor, destructor, or type conversion before '(' token
  202 | func (Event Events) Less(i, j int) bool {
      |      ^
a.cc:220:6: error: expected constructor, destructor, or type conversion before '(' token
  220 | func (Event Events) Swap(i, j int) { Event[i], Event[j] = Event[j], Event[i] }
      |      ^
a.cc:222:1: error: 'var' does not name a type
  222 | var ord Events
      | ^~~