ミラティブ プログラミングコンテスト2025(AtCoder Beginner Contest 414)
G
AtCoder Express 4
AtCoder
⌀ 3020
原题
翻译中…

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.

翻译中…

样例

Input #1
6 3
0 20 50 90 110 150
1 2 5 6 100
1 1 2 3 10000
6 6 1 2 30
Output #1
410 10050 -1 210 250
You can travel to station $2$ as follows: 1. Board the $1$st express train at station $1$ and get off at station $6$. The fare is $c_1+|x_1-x_6|=100+|0-150|=250$. 2. Board the $3$rd express train at station $6$ and get off at station $2$. The fare is $c_3+|x_6-x_2|=30+|150-20|=160$. The total fare in this case is $410$, which is the minimum. You cannot travel to station $4$.
Input #2
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
Output #2
149045 284335 65311 255373 225725 220523 253207 -1 182483
题目信息
题号
abc414_g
时间限制
2.5 s
内存限制
1024 MB

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