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.

题目链接:http://codeforces.com/contest/740/problem/C


题意:定义mex为一个集合里面没有出现的最小的非负整数,有一个长度为n的集合,m个区间,现在要使得m各区间的最小的mex最大。

思路:最小的mex就是最小的区间长度。因为每个区间0,1,2,3...,才能使得最小的mex最大。当时最小的区间限制了长度,所以最小的mex最大为最小的区间长度x。长度为n的数组只要0,1,2,3,...x-2,x-1循环至n个数。因为每个区间的都是大于等于x的,所以无论怎么取区间都会有0~x-1。

代码:

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int Max=1e6+;
for(int i=; i<m; i++)
{
int l,r;
scanf("%d%d",&l,&r);
Max=min(Max,r-l+);
}
cout<<Max<<endl;
int sign=;
for(int i=; i<n; i++)
{
cout<<sign<<" ";
sign++;
sign=sign%Max;
}
cout<<endl;
return ;
}

Codeforces 740C. Alyona and mex 思路模拟的更多相关文章

  1. CodeForces 740C Alyona and mex

    构造. 比较骚的构造题.肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$ ...

  2. CodeForces 682B Alyona and Mex (排序+离散化)

    Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...

  3. CodeForces 682B Alyona and Mex (题意水题)

    题意:给定一个序列,你可以对这里面的数用小于它的数来代替,最后让你求,改完后的最大的序列中缺少的最小的数. 析:这个题,读了两个多小时也没读懂,要是读懂了,肯定能做出来...没什么可说的,就是尽量凑1 ...

  4. Codeforces Round #381 (Div. 1) A. Alyona and mex 构造

    A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...

  5. Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题

    B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...

  6. Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)

    C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...

  7. Codeforces Round #358 (Div. 2)B. Alyona and Mex

    B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Alyona and mex

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

随机推荐

  1. js实现继承的两种方式

    这是面试时面试官会经常问到问题: js的继承方式大致可分为两种:对象冒充和原型方式: 一.先说对象冒充,又可分为3种:临时属性方式.call().apply(): 1.临时属性方式: 当构造对象son ...

  2. 自动获取MyEcilipse注册名和注册码的方法

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; //在MyEc ...

  3. 使用spring手动获取Bean的时候,不能强转回它自己。

    这个问题好像有点长,描述一下: 就是通过类名的方式获取Bean后,得到一个Object对象,但是这个Object不能再强转回Bean了.抛出的异常时类型转换异常.  java.lang.ClassCa ...

  4. dev_set_draw的fill和margin模式

    注意:分别观察两张填充模式,一种是内部填充,一种是边缘填充.还有一种缺省的填充. Name dev_set_draw — Define the region fill mode. Signature ...

  5. AIX 环境下Telnet返回提示所有端口已经被占用,处理方法

    IBM AIX v5.3操作系统环境Telnet返回提示所有端口已经被占用 可以按以下步骤进行检查和处理 1,以下命令检查pty0是否可用 #lsdev -Cl pty0 2,以下命令检查telnet ...

  6. MySQL_订单类型细分_20161222

    #目前在做一个各城市日订单角度的对比分析,因此需要对订单类型进行一下规整.由于App上产品活动许多,查询了多个表,将订单类型规则进行了统一,优惠券和满减券不能同时使用,创建的这两个表都是以订单ID为k ...

  7. Microsoft CRM 2013 设置默认组织 default organization

    Microsoft CRM 2013 在部署管理器里没有设置默认组织的功能(以前4.0是有的),所以如果安装了多组织并且某些用户在多组织里同时存在这就涉及默认组织的设置问题,或者在安装outlook ...

  8. iOS 当请求到的数据是double类型,会失去精准度,并且去掉小数点后的0

    首先请求到的数据都会变成字符串,先将字符串转化为double类型 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px Menlo; color: ...

  9. SecureCRT和SecureFx设置中文乱码

    SecureCRT和SecureFx设置中文乱码 SecureCRT和SecureFx连接服务器时中文显示乱码,找了好多资料好久都没整出来,后来整出来了,因此把个人的解决办法提供出来,已变帮助更多的人 ...

  10. cordova常用资料源

    cordova的中文资料https://github.com/CordovaCn/CordovaCn 官方文档: http://cordova.apache.org/docs/en/latest/ E ...