AtCoder Regular Contest 190 (Div. 1)
A
Inside or Outside
AtCoder
⌀ 1381
原题
←B →
翻译中…

Problem Statement

翻译中…

There is an integer sequence $x = (x_1, \ldots, x_N)$, which is initialized with $x_1 = \cdots = x_N = 0$.

翻译中…

You will perform $M$ operations on this integer sequence. In the $i$-th operation, you are given an integer pair $(L_i, R_i)$ such that $1 \leq L_i \leq R_i \leq N$, and you must perform exactly one of the following three operations:

翻译中…
  • Operation $0$: Do nothing. This operation incurs a cost of $0$.
  • Operation $1$: For each integer $j$ with $1 \leq j \leq N$, if $L_i \leq j \leq R_i$ holds, set $x_j = 1$. This operation incurs a cost of $1$.
  • Operation $2$: For each integer $j$ with $1 \leq j \leq N$, if $L_i \leq j \leq R_i$ does not hold, set $x_j = 1$. This operation incurs a cost of $1$.
翻译中…

Your goal is to make $x_1 = \cdots = x_N = 1$ hold at the end. Determine whether this goal can be achieved. If it can be achieved, present one way to achieve it where the total cost of the operations is minimized.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 1000000$
  • $1 \leq M \leq 200000$
  • $1 \leq L_i \leq R_i \leq N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
L_1 R_1
\vdots
L_M R_M

翻译中…

Output

翻译中…

If the goal is not achievable, print -1.

翻译中…

If the goal is achievable, print one way to achieve it where the total cost of the operations is minimized, in the following format, where $K$ is the minimum total cost of the operations, and $\mathrm{op}_i$ is the type of operation ($0$, $1$, or $2$) chosen for the $i$-th operation.

翻译中…

K
\mathrm{op}_1 \cdots \mathrm{op}_M

翻译中…

If there are multiple ways that minimize the total cost, printing any one of them is accepted.

翻译中…

样例

Input #1
5 4
2 4
3 5
1 4
2 5
Output #1
2
2 0 1 0
In the sample output, $x$ changes as follows: - Initially, $x = (0,0,0,0,0)$. - In the 1st operation, Operation $2$ is performed. $x_1$ and $x_5$ become 1, so $x = (1,0,0,0,1)$. - In the 2nd operation, Operation $0$ is performed. $x$ remains $(1,0,0,0,1)$. - In the 3rd operation, Operation $1$ is performed. $x_1, x_2, x_3, x_4$ become 1, so $x = (1,1,1,1,1)$. - In the 4th operation, Operation $0$ is performed. $x$ remains $(1,1,1,1,1)$.
Input #2
5 4
1 3
1 5
2 4
3 5
Output #2
1
0 1 0 0
Input #3
5 2
1 3
2 5
Output #3
2
1 1
Input #4
5 2
1 3
2 4
Output #4
-1
题目信息
题号
arc190_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。