#P7984. [USACO21DEC] Tickets P

    ID: 9102 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP线段树USACO2021图论建模最短路

[USACO21DEC] Tickets P

Problem Description

Bessie is going on a hiking trip! The route she is currently traveling consists of NN checkpoints numbered 1N1\ldots N (1N1051\le N\le 10^5).

There are KK (1K1051\le K\le 10^5) tickets available for purchase. Ticket ii can be bought at checkpoint cic_i (1ciN1\le c_i\le N) for price pip_i (1pi1091\le p_i\le 10^9), and it allows entry to all checkpoints in [ai,bi][a_i,b_i] (1aibiN1\le a_i\le b_i\le N). Before entering any checkpoint, Bessie must have already bought a ticket that allows her to enter that checkpoint. Once Bessie can travel to a checkpoint, she can return to that checkpoint at any time in the future.

For each i[1,N]i\in [1,N], if Bessie can initially only enter checkpoint ii, output the minimum total cost required to be able to enter checkpoints 11 and NN. If it is impossible, output 1-1.

Input Format

The first line contains NN and KK.

The next KK lines each describe one ticket. For each 1iK1\le i\le K, line ii contains four integers cic_i, pip_i, aia_i, and bib_i.

Output Format

Output NN lines. On each line, output the answer for one starting checkpoint.

7 6
4 1 2 3
4 10 5 6
2 100 7 7
6 1000 1 1
5 10000 1 4
6 100000 5 6
-1
-1
-1
1111
10100
110100
-1

Hint

[Sample Explanation]

If Bessie starts from checkpoint i=4i=4, then one way to buy tickets to be able to enter checkpoints 11 and NN is:

Buy the first ticket at checkpoint 44, allowing Bessie to enter checkpoints 22 and 33.

Buy the third ticket at checkpoint 22, allowing Bessie to enter checkpoint 77.

Go back to checkpoint 44 and buy the second ticket, allowing Bessie to enter checkpoints 55 and 66.

Buy the fourth ticket at checkpoint 66, allowing Bessie to enter checkpoint 11.

[Constraints]

  • Test cases 1-7 satisfy N,K1000N, K\le 1000.
  • Test cases 8-19 have no additional constraints.

Translated by ChatGPT 5