Codeforces Round #381 (Div. 2)C - Alyona and mex

C. Alyona and mex
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


大体题意是要构造一个序列,使得他给你的那m个查询区间里的最小的mex最大化,mex是不在这个区间里的最小非负数,要使最小的最大化,最小的那个应该是区间范围长度最小的,让他最大化,最大也就是区间的长度,确定好了这个最小值,就可以构造了。。。。。

假设已经确定好了那个最小值是x,

序列:0 1 2 ... x-1 0 1 2 ...x-1 ........一直有n个点,

为什么这么构造呢。。。。不会推理,灵光一现。。证明就很简单了,能看出来,对于这个序列,区间长度大于等于x的区间,无论怎么覆盖都肯定能至少把0~x-1覆盖一遍

#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
	int i,t,n,m,l,r,minn=inf;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&l,&r);
		minn=min(minn,r-l);
	}
	minn++;
	printf("%d\n",minn);
	for(t=0,i=0;i<n;i++)
	{
		if(t==minn)
		{
			t=0;
		}
		printf("%d",t);
		t++;
		if(i==n-1)
		printf("\n");
		else
		printf(" ");
	}
}

第一次cf排名这么高。。。。。。。虽然我菜,但是我水啊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值