Problem Statement
In AtCoder Kingdom, there is a railway line extending east-west, and this line has stations $1,2,\ldots,N$. Station $i\ (1\leq i\leq N)$ is located at coordinate $x_i$ $(x_1 < x_2 < \ldots < x_N)$.
On this line, AtCoder Express company operates $M$ types of express trains.
The $i$-th type of express train operates as follows:
- You can board this train at one of the stations
$l_i,l_i+1,\ldots,r_i$. - You can get off this train at one of the stations
$L_i, L_i+1, \ldots, R_i$. Here, the train travels in one direction, either east or west, satisfying$r_i\lt L_i$or$R_i\lt l_i$. - The fare consists of a base fare of
$c_i$plus an amount based on the distance from the boarding station to the destination station. Specifically, when traveling from station$s\ (l_i\leq s\leq r_i)$to station$t\ (L_i\leq t\leq R_i)$, the fare is$c_i+|x_s-x_t|$.
You are currently at station $1$. For each $k\ (2\leq k\leq N)$, determine whether you can travel from station $1$ to station $k$ by transferring between express trains, and if you can travel, find the minimum total fare required for the travel.
Constraints
$2\leq N\leq 10^5$$1\leq M\leq 10^5$$0\leq x_1 < x_2 < \ldots < x_N \leq 10^{12}$$1\leq l_i\leq r_i\leq N, 1\leq L_i\leq R_i\leq N$$r_i\lt L_i$or$R_i\lt l_i$.$1\leq c_i\leq 10^{12}$- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M
x_1 x_2 \ldots x_N
l_1 r_1 L_1 R_1 c_1
l_2 r_2 L_2 R_2 c_2
\vdots
l_M r_M L_M R_M c_M
Output
Output the answer in the following format:
\mathrm{ans}_2 \mathrm{ans}_3 \ldots \mathrm{ans}_N
$\mathrm{ans}_i$ is the answer for $k=i$. If you can travel from station $1$ to station $i$, $\mathrm{ans}_i$ is the minimum total fare required for the travel; otherwise, $\mathrm{ans}_i$ is -1.
样例
6 3
0 20 50 90 110 150
1 2 5 6 100
1 1 2 3 10000
6 6 1 2 30
410 10050 -1 210 250
10 5
4427 6839 17992 39701 46954 76602 81804 91814 95651 95895
3 4 10 10 60978
1 1 4 4 30037
9 10 7 8 66643
4 4 1 2 50872
8 10 3 7 23949
149045 284335 65311 255373 225725 220523 253207 -1 182483
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。