CF739A.Alyona and mex

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.

Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers l__i and r__i, and its elements are a[l__i], a[l__i + 1], ..., a[r__i].

Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.

You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.

The mex of a set S is a minimum possible non-negative integer that is not in S.

Alyona 的母亲想送给她一个由 nn 个非负整数组成的数组。该数组需满足“特殊”要求。

Alyona 是一位任性的女孩,因此在收到数组后,她会检查其中的 mm 个子数组。子数组是指原数组中若干连续元素组成的集合。第 ii 个子数组由两个整数 lil_i 和 rir_i 描述,其元素为 a[li], a[li+1], …, a[ri]a[l_i],\ a[l_i + 1],\ \dots,\ a[r_i]。

Alyona 将对每个选定的子数组计算其 mex 值。然后,她将在这些 mm 个 mex 值中找出最小值。她希望这个最小 mex 尽可能大。

你需要构造一个长度为 nn 的数组 aa,使得 Alyona 所选的 mm 个子数组对应的 mex 值中的最小值尽可能大。

集合 SS 的 mex 定义为:不在 SS 中的最小非负整数。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 105).

The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers l__i and r__i (1 ≤ l__i ≤ r__i ≤ n), that describe the subarray a[l__i], a[l__i + 1], ..., a[r__i].

第一行包含两个整数 nn 和 mm(1 ≤ n, m ≤ 1051 \leq n, m \leq 10^5)。

接下来的 mm 行描述 Alyona 选择的子数组。其中第 ii 行包含两个整数 lil_i 和 rir_i(1 ≤ li ≤ ri ≤ n1 \leq l_i \leq r_i \leq n),表示子数组 a[li], a[li + 1], …, a[ri]a[l_i],\ a[l_i + 1],\ \dots,\ a[r_i]。

输出格式

In the first line print single integer — the maximum possible minimum mex.

In the second line print n integers — the array a. All the elements in a should be between 0 and 109.

It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.

If there are multiple solutions, print any of them.

第一行输出一个整数——可能的最大最小 mex 值。

第二行输出 nn 个整数——数组 aa。aa 中所有元素均应在 00 到 10910^9 之间。

保证存在一个最优解,其中 aa 的所有元素均在 00 到 10910^9 之间。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    5 3
    1 3
    2 5
    4 5

    输出#1

    2
    1 0 2 1 0
  • 输入#2

    4 2
    1 4
    2 4

    输出#2

    3
    5 2 0 1

说明/提示

The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.

第一个例子:子数组 (1, 3)(1,\,3) 的 mex 等于 33,子数组 (2, 5)(2,\,5) 的 mex 等于 33,子数组 (4, 5)(4,\,5) 的 mex 也等于 22,因此 Alyona 所选子数组中最小的 mex 值为 22。

输入解题思路,AI测评打分。不知道怎么写?

首页