CF739A.Alyona and mex

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

Alyona is a capricious girl so after she gets the array, she inspects mm of its subarrays. Subarray is a set of some subsequent elements of the array. The ii -th subarray is described with two integers lil_{i} and rir_{i} , and its elements are a[li],a[li+1],...,a[ri]a[l_{i}],a[l_{i}+1],...,a[r_{i}] .

Alyona is going to find mex for each of the chosen subarrays. Among these mm 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 aa of nn elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.

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

输入格式

The first line contains two integers nn and mm ( 1<=n,m<=1051<=n,m<=10^{5} ).

The next mm lines contain information about the subarrays chosen by Alyona. The ii -th of these lines contains two integers lil_{i} and rir_{i} ( 1<=li<=ri<=n1<=l_{i}<=r_{i}<=n ), that describe the subarray a[li],a[li+1],...,a[ri]a[l_{i}],a[l_{i}+1],...,a[r_{i}] .

输出格式

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

In the second line print nn integers — the array aa . All the elements in aa should be between 00 and 10910^{9} .

It is guaranteed that there is an optimal answer in which all the elements in aa are between 00 and 10910^{9} .

If there are multiple solutions, print any of them.

输入输出样例

  • 输入#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)(1,3) is equal to 33 , the mex of the subarray (2,5)(2,5) is equal to 33 , the mex of the subarray (4,5)(4,5) is equal to 22 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 22 .

首页