Codeforces Round 176 (Div. 1)
D
Tourists
Codeforces
2600
原题
← CE →
翻译中…

A double tourist path, located at a park in Ultima Thule, is working by the following principle:

翻译中…
  • We introduce the Cartesian coordinate system.
  • At some points of time there are two tourists going (for a walk) from points $( - 1, 0)$ and $(1, 0)$ simultaneously. The first one is walking from $( - 1, 0)$, the second one is walking from $(1, 0)$.
  • Both tourists in a pair move at the same speed $1$ (distance unit per second), the first one moves along line $*x* = - 1$, the second one moves along line $*x* = 1$, both of them are moving in the positive direction of the $*Oy*$ axis.
  • At some points of time walls appear. Wall $(*l*_{*i*}, *r*_{*i*})$ is a segment between points $(0, *l*_{*i*})$ and $(0, *r*_{*i*})$. Each wall appears immediately.
翻译中…

The Ultima Thule government wants to learn this for each pair of tourists that walk simultaneously: for how long (in seconds) will they not see each other? Two tourists don't see each other if the segment that connects their positions on the plane intersects at least one wall. Two segments intersect if they share at least one point. We assume that the segments' ends belong to the segments.

翻译中…

Help the government count the required time. Note that the walls can intersect (in any way) or coincide.

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$) — the number of pairs of tourists and the number of built walls. The next $*m*$ lines contain three space-separated integers $*l*_{*i*}$, $*r*_{*i*}$ and $*t*_{*i*}$ each ($0 ≤ *l*_{*i*} < *r*_{*i*} ≤ 10^{9}$, $0 ≤ *t*_{*i*} ≤ 10^{9}$) — the wall ends and the time it appeared. The last line contains $*n*$ distinct space-separated strictly increasing integers $*q*_{1}, *q*_{2}, ..., *q*_{*n*}$ ($0 ≤ *q*_{*i*} ≤ 10^{9}$) — the points of time when pairs of tourists walk.

翻译中…

All points of time are given in seconds.

翻译中…

Output

翻译中…

For each pair of tourists print on a single line a single integer — the time in seconds when the two tourists from the corresponding pair won't see each other. Print the numbers in the order in which the they go in the input.

翻译中…

样例

Input #1
2 2
1 4 3
3 6 5
0 1
Output #1
2
4
InputCopy OutputCopy
Input #2
3 3
0 3 4
0 1 2
2 4 0
1 3 4
Output #2
2
4
4
InputCopy OutputCopy
题目信息
题号
286D
时间限制
1 s
内存限制
256 MB
标签
数据结构
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。