#P11024. [COTS 2020] 定序 Redoslijed

    ID: 12437 远端评测题 4000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心2020线段树Special JudgeO2优化COCI(克罗地亚)

[COTS 2020] 定序 Redoslijed

Background

Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D1T2。4s,0.5G\texttt{4s,0.5G}

Acknowledgement: SPJ by

https://www.luogu.com.cn/user/739552

Problem Description

You are painting on a wooden board of length NmN\,\mathrm{m}。The board is divided from left to right into NN cells, and each cell is 1m1\,\mathrm{m} long。

It is known that MM strokes were painted on the board。The ii-th stroke paints cells liril_i\sim r_i into color cic_i

Given the final state of the board after all painting, construct an order of operations such that after performing the operations once, the board becomes exactly the given final state, or report that there is no solution。

Input Format

The first line contains two positive integers N,MN,M

The next MM lines each contain three integers li,ri,cil_i,r_i,c_i, describing a painting operation。

The next line contains NN integers。The ii-th integer denotes the final color bib_i of the ii-th cell。In particular, if bi=0b_i=0, it means the cell with bib_i is unpainted.

Output Format

If there is no solution, output NE\texttt{NE} (Croatian for “No”)。

Otherwise, output DA\texttt{DA} (Croatian for “Yes”) on the first line; on the second line output a permutation of 1M1\sim M indicating the painting order。

If there are multiple solutions, any one is acceptable。

6 5
3 5 5
1 1 6
1 3 2
1 4 7
4 6 6
6 2 5 5 5 6
DA
4 5 3 1 2

14 6
6 9 4
12 13 6
2 3 5
1 14 3
5 6 9
9 12 8
3 5 5 3 9 4 4 4 8 8 8 6 6 3
DA
4 5 1 6 2 3
15 5
7 8 3
10 14 5
4 7 2
3 12 1
5 9 4
0 0 1 2 4 4 3 3 4 5 1 1 5 5 0
NE

Hint

For 100%100\% of the testdata, it is guaranteed that:

  • 1N,M5×1051\le N,M\le 5\times 10^5
  • 1liriN1\le l_i\le r_i\le N
  • 1ci5×1051\le c_i\le 5\times 10^5
  • 0bi5×1050\le b_i\le 5\times 10^5
Subtask ID NN\le Special property Score
1 1 99 5 5
2 2 50005\,000 A 10 10
3 3 5×1055\times 10^5 25 25
4 4 50005\, 000 12 12
5 5 5×1055\times 10^5 B 16 16
6 6 32 32
  • Special property A: all cic_i are pairwise distinct。
  • Special property B: 1ci51\le c_i\le 5

Translated by ChatGPT 5