← Home
```go
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"sort"
)

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
}

func nextInt() int64 {
	scanner.Scan()
	var res int64
	s := scanner.Bytes()
	var sign int64 = 1
	var i int = 0
	if len(s) > 0 && s[0] == '-' {
		sign = -1
		i++
	}
	for ; i < len(s); i++ {
		res = res*10 + int64(s[i]-'0')
	}
	return res * sign
}

type WallAdd struct {
	l, r, t int64
}

type Event struct {
	time       int64
	slope_diff int64
	int_diff   int64
}

type Item struct {
	t, r int64
}

type MinHeap []Item

func (h MinHeap) Len() int           { return len(h) }
func (h MinHeap) Less(i, j int) bool { return h[i].t < h[j].t }
func (h MinHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *MinHeap) Push(x interface{}) {
	*h = append(*h, x.(Item))
}
func (h *MinHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	n := int(nextInt())
	m := int(nextInt())

	walls := make([]WallAdd, m)
	y_coords := make([]int64, 0, 2*m)
	for i := 0; i < m; i++ {
		walls[i].l = nextInt()
		walls[i].r = nextInt()
		walls[i].t = nextInt()
		y_coords = append(y_coords, walls[i].l, walls[i].r)
	}

	sort.Slice(walls, func(i, j int) bool {
		return walls[i].l < walls[j].l
	})

	sort.Slice(y_coords, func(i, j int) bool { return y_coords[i] < y_coords[j] })
	k := 0
	for i := 0; i < len(y_coords); i++ {
		if i == 0 || y_coords[i] != y_coords[i-1] {
			y_coords[k] = y_coords[i]
			k++
		}
	}
	y_coords = y_coords[:k]

	h := &MinHeap{}
	heap.Init(h)

	var events []Event
	wallIdx := 0

	for i := 0; i < k-1; i++ {
		for wallIdx < m && walls[wallIdx].l == y_coords[i] {
			heap.Push(h, Item{t: walls[wallIdx].t, r: walls[wallIdx].r})
			wallIdx++
		}

		for h.Len() > 0 && (*h)[0].r <= y_coords[i] {
			heap.Pop(h)
		}

		if h.Len() > 0 {
			min_t := (*h)[0].t
			A := y_coords[i]
			B := y_coords[i+1]

			events = append(events, Event{
				time:       min_t - B,
				slope_diff: 1,
				int_diff:   -(min_t - B),
			})
			events = append(events, Event{
				time:       min_t - A,
				slope_diff: -1,
				int_diff:   min_t - A,
			})
		}
	}

	sort.Slice(events, func(i, j int) bool {
		return events[i].time < events[j].time
	})

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	eventIdx := 0
	var current_slope int64 = 0
	var current_intercept int64 = 0

	for j := 0; j < n; j++ {
		q := nextInt()
		for eventIdx < len(events) && events[eventIdx].time <= q {
			current_slope += events[eventIdx].slope_diff
			current_intercept += events[eventIdx].int_diff
			eventIdx++
		}
		ans := current_slope*q + current_intercept
		fmt.Fprintln(out, ans)
	}
}
```