codeforces739A. Alyona and mex

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 li and ri, and its elements are a[li], a[li + 1], ..., a[ri].

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.

Input

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 li and ri (1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].

Output

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.

Examples
Input
5 3
1 3
2 5
4 5
Output
2
1 0 2 1 0
Input
4 2
1 4
2 4
Output
3
5 2 0 1

Note

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 0 2 1 0.然后就是看输入,第一组数1 3,就看区间(1  3) 是1 0 2不存在于这个子数列的最小元素是3,第二组(2 5),是0 2 1,同样不存在于这个子数列的最小值也是3,然后(4 5 )是1   0,不存在于这个子数列的最小元素是2,所以最后输出这个最小的。最后输出不是唯一的,所以其实这个题就是求区间的最小长度,然后这个长度是mex,然后随便输出不能大于mex的n个数就好了。
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010][2];
int b[10010];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int i,j;
	int min=0x3f3f3f3f;
	for(i=0;i<m;i++)
	{
		for(j=0;j<2;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=0;i<m;i++)
	{
		if((a[i][1]-a[i][0])<min)
			min=a[i][1]-a[i][0];
	}
	printf("%d\n",min+1);
	int p=0,q=0;
	for(int t=0;t<n;t++)
	{

	
		if(p<(min+1))
		{
		cout<<p<<" ";
		p++;
		}
		if(p==(min+1))   p=0;
	}
	return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值