P11024 [COTS 2020] Ordering Redoslijed

Background

Translated from [Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection)](https://hsin.hr/pripreme2020/) D1T2。$\texttt{4s,0.5G}$。 Acknowledgement: SPJ by @[mygr](https://www.luogu.com.cn/user/739552)。

Description

You are painting on a wooden board of length $N\,\mathrm{m}$。The board is divided from left to right into $N$ cells, and each cell is $1\,\mathrm{m}$ long。 It is known that $M$ strokes were painted on the board。The $i$-th stroke paints cells $l_i\sim r_i$ into color $c_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,M$。 The next $M$ lines each contain three integers $l_i,r_i,c_i$, describing a painting operation。 The next line contains $N$ integers。The $i$-th integer denotes the final color $b_i$ of the $i$-th cell。**In particular, if $b_i=0$, it means the cell with $b_i$ is unpainted.**

Output Format

If there is no solution, output $\texttt{NE}$ (Croatian for “No”)。 Otherwise, output $\texttt{DA}$ (Croatian for “Yes”) on the first line; on the second line output a permutation of $1\sim M$ indicating the painting order。 If there are multiple solutions, any one is acceptable。

Explanation/Hint

For $100\%$ of the testdata, it is guaranteed that: - $1\le N,M\le 5\times 10^5$; - $1\le l_i\le r_i\le N$; - $1\le c_i\le 5\times 10^5$; - $0\le b_i\le 5\times 10^5$。 | Subtask ID | $N\le $ | Special property | Score | | :--: | :--: | :--: | :--: | | $ 1 $ | $9$ | |$ 5 $ | | $ 2 $ | $5\,000$ | A |$ 10 $ | | $ 3 $ | $5\times 10^5$ | A |$ 25 $ | | $ 4 $ | $5\, 000$ || $ 12 $ | | $ 5 $ | $5\times 10^5$ | B| $ 16 $ | | $ 6 $ | $5\times 10^5$ || $ 32 $ | - Special property A: all $c_i$ are pairwise distinct。 - Special property B: $1\le c_i\le 5$。 Translated by ChatGPT 5