#P15958. [ICPC 2018 Jakarta R] Lexical Sign Sequence

[ICPC 2018 Jakarta R] Lexical Sign Sequence

题目描述

Andi likes numbers and sequences, especially, sign sequences. A sign sequence is a sequence which consists of 1-1 and 11. Andi is a curious person, thus, he wants to build a sign sequence which length is NN (the positions are numbered from 11 to NN, inclusive).

However, Andi also likes some challenges. Therefore, he prefilled some positions in the sequence with 1-1 or 11 (the number in these positions cannot be changed). Andi also wants the sequence to fulfill KK constraints. For each constraint, there are 3 numbers: AiA_i, BiB_i, and CiC_i. This means that the sum of numbers which position is in the range [Ai,Bi][A_i, B_i] (inclusive) must be at least CiC_i.

Sounds confusing, right? It is not done yet. Since there can be many sequences that fulfill all the criteria above, Andi wants the sequence to be lexicographically smallest. Sequence XX is lexicographically smaller than sequence YY if and only if there exists a position ii where Xi<YiX_i < Y_i and Xj=YjX_j = Y_j for all j<ij < i.

Find the sequence Andi wants.

输入格式

Input begins with a line containing two integers: NN KK (1N1000001 \leq N \leq 100000; 0K1000000 \leq K \leq 100000) representing the length of the sequence and the number of constraints, respectively. The second line contains NN integers: PiP_i (1Pi1-1 \leq P_i \leq 1). If Pi=0P_i = 0, then the ithi^{th} position in the sequence is not prefilled, otherwise the ithi^{th} position in the sequence is prefilled by PiP_i. The next KK lines, each contains three integers: AiA_i BiB_i CiC_i (1AiBiN1 \leq A_i \leq B_i \leq N; NCiN-N \leq C_i \leq N) representing the ithi^{th} constraint.

输出格式

Output contains NN integers (each separated by a single space) in a line representing the sequence that Andi wants if there exists such sequence, or “Impossible” (without quotes) otherwise.

3 2
0 0 0
1 2 2
2 3 -1
1 1 -1
3 2
0 -1 0
1 2 2
2 3 -1
Impossible

提示

Explanation for the sample input/output #1

Both sequences [1,1,1][1, 1, -1] and [1,1,1][1, 1, 1] satisfy the prefilled conditions and the given KK constraints. The former is lexicographically smaller.

Explanation for the sample input/output #2

The second position is already prefilled with 1-1, so it is impossible to fulfill the first constraint. There is no valid sequence in this case.