102166: [AtCoder]ABC216 G - 01Sequence

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

Consider a sequence of length $N$ consisting of 0s and 1s, $A=(A_1,A_2,\dots,A_N)$, that satisfies the following condition.

For every $i=1,2,\dots,M$, there are at least $X_i$ occurrences of 1 among $A_{L_i}, A_{L_i+1}, \dots, A_{R_i}$.

Print one such sequence with the fewest number of occurrences of 1s.

There always exists a sequence that satisfies the condition under the Constraints.

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq M \leq \min(2 \times 10^5, \frac{N(N+1)}{2} )$
  • $1 \leq L_i \leq R_i \leq N$
  • $1 \leq X_i \leq R_i-L_i+1$
  • $(L_i,R_i) \neq (L_j,R_j)$ if $i \neq j$.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$
$L_1$ $R_1$ $X_1$
$L_2$ $R_2$ $X_2$
$\vdots$
$L_M$ $R_M$ $X_M$

Output

Print a sequence $A$ consisting of 0s and 1s, with spaces in between.

$A_1$ $A_2$ $\dots$ $A_N$

It must satisfy all the requirements above.


Sample Input 1

6 3
1 4 3
2 2 1
4 6 2

Sample Output 1

0 1 1 1 0 1 

Another acceptable output is 1 1 0 1 1 0.
On the other hand, 0 1 1 1 1 1, which has more than the fewest number of 1s, is unacceptable.


Sample Input 2

8 2
2 6 1
3 5 3

Sample Output 2

0 0 1 1 1 0 0 0 

Input

题意翻译

你需要构造出一个长度为 $n$ 的 $01$ 序列,满足 $m$ 个限制 $(l_i,r_i,x_i)$:在 $[l_i,r_i]$ 这段区间内,序列上 $1$ 的个数不小于 $x_i$。**你需要保证你的方案中包含 $1$ 的个数最小。** 数据保证有解。 $1 \le n,m \le 2 \times 10^5$

Output

分数:600分

问题描述

考虑一个由0和1组成的长度为N的序列,$A=(A_1,A_2,\dots,A_N)$,满足以下条件。

对于每个$i=1,2,\dots,M$,在$A_{L_i}, A_{L_i+1}, \dots, A_{R_i}$中至少有$X_i$个1。

打印满足条件的具有**最少**数量的1的序列。

在约束条件下,总存在满足条件的序列。

约束条件

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq M \leq \min(2 \times 10^5, \frac{N(N+1)}{2} )$
  • $1 \leq L_i \leq R_i \leq N$
  • $1 \leq X_i \leq R_i-L_i+1$
  • 如果$i \neq j$,则$(L_i,R_i) \neq (L_j,R_j)$。
  • 输入中的所有值都是整数。

输入

输入以标准输入的以下格式给出:

$N$ $M$
$L_1$ $R_1$ $X_1$
$L_2$ $R_2$ $X_2$
$\vdots$
$L_M$ $R_M$ $X_M$

输出

打印由0和1组成的序列$A$,之间用空格隔开。

$A_1$ $A_2$ $\dots$ $A_N$

必须满足上述所有要求。


样例输入1

6 3
1 4 3
2 2 1
4 6 2

样例输出1

0 1 1 1 0 1 

另一种可接受的输出是1 1 0 1 1 0
另一方面,具有超过最少数量的1的0 1 1 1 1 1是不可接受的。


样例输入2

8 2
2 6 1
3 5 3

样例输出2

0 0 1 1 1 0 0 0 

加入题单

算法标签: