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. Ms sql行转列。汇总

    SQL行转列汇总 PIVOT 用于将列值旋转为列名(即行转列),在 SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT 的一般语法是:PIVOT(聚合函数(列) FOR 列 ...

  2. HttpClient Get/Post方式调用Http接口

    本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...

  3. PIC32MZ tutorial -- OC Interrupt

    In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...

  4. js变量搜索(先局部,后全局;先解析,后赋值)

    var a=10; (function(){ alert(a); })() 变量先搜索局部,没有局部变量,会搜索全局变量 var a=10; (function(){ var a=20; alert( ...

  5. 14.S5PV210串行通信编程实战

    1.整个程序流程分析(1)整个串口通信相关程序包含2部分:uart_init负责初始化串口,uart_putc负责发送一个字节2.串口控制器初始化关键步骤(1)初始化串口的Tx和Rx引脚所对应的GPI ...

  6. Linux Shell ---系统命令(1)

    date命令 功能说明:显示或设置系统时间与日期. 语 法: date [-d <字符串>][-u][+%H%I%K%l%M%P%r%s%S%T%X%Z%a%A%b%B%c%d%D%j%m ...

  7. Nodejs学习(三)-安装nodejs supervisor,提高点效率吧。

    安装好了express准备写项目,可是发现随便改一下js都要使用npm start重新启动才能生效,这个很不好,搜索一下发现有这么一个模块supervisor.那就安装一下吧. 1.安装,这个必须是全 ...

  8. php中的魔术方法

    __construct 构造器是一个魔术方法,当对象被实例化时它会被调用.在一个类声明时它常常是第一件做的事但是没得必要他也像其他任何方法在类中任何地方都可以声明,构造器也能像其他方法样继承.如果我们 ...

  9. ActiveX: 如何用.inf和.ocx文件生成cab文件

    ActiveX: 如何用.inf和.ocx文件生成cab文件  

  10. Net accounts命令

    Net accounts 将用户帐户数据库升级并修改所有帐户的密码和登录请求. 语法 net accounts [/forcelogoff:{minutes | no}] [/minpwlen:len ...