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 liand 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.

解题思路:

之前没看懂题。。后面看了下题解,就是求最小区间的mex,mex就是没在区间出现过的最小正整数,所以只要选择最小的区间就可以,他的mex最小,至于其他的区间直接按照0.。ans-1,0.。ans-1,这样取就可以了。

实现代码:

#include<iostream>
using namespace std; int main()
{
int m,n,i,ans,a,b;
cin>>m>>n;
for(i=;i<n;i++){
cin>>a>>b;
ans = min(ans,b-a);
}
ans++;
cout<<ans<<endl;
cout<<%ans;
for(i=;i<=m;i++){
cout<<" "<<i%ans;
}
return ;
}

Codeforces Round #381 (Div. 2)C Alyona and mex的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #381 (Div. 2) C. Alyona and mex(无语)

    题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最 ...

  4. 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 ...

  5. Codeforces Round #381 (Div. 1) B. Alyona and a tree dfs序 二分 前缀和

    B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree ...

  6. Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想

    题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...

  7. Codeforces Round #381 (Div. 2)D. Alyona and a tree(树+二分+dfs)

    D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is ...

  8. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  9. Codeforces Round #381 (Div. 2)A. Alyona and copybooks(dfs)

    A. Alyona and copybooks Problem Description: Little girl Alyona is in a shop to buy some copybooks f ...

随机推荐

  1. Python、Lua和Ruby三大语言脚本哪家强?

    这三种语言中的哪一种更合适你的项目?很大程度取决于你想达到什么样的目标.作为一书的结尾,在这一节里,我会描述一下它们各自的优点和不足.   Python的优点和不足 Python的优点如下: 1. P ...

  2. 4.5《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)—第四章小结

    本章相关重要命令总结在Table 6. 命令 描述 示例 mkdir <name> 创建某目录 $ mkdir foo pwd 显示当前所在目录 $ pwd cd <dir> ...

  3. Caffe源码中math_functions文件分析

    Caffe源码(caffe version:09868ac , date: 2015.08.15)中有一些重要文件,这里介绍下math_functions文件. 1.      include文件: ...

  4. springboot 发送邮件+模板+附件

    package com.example.demo; import org.junit.Test;import org.junit.runner.RunWith;import org.springfra ...

  5. SSL踩坑ERR_SSL_VERSION_OR_CIPHER_MISMATCH

    最近公司项目开发了一个微信小程序,并且部署测试OK,由于微信小程序调用的后端接口必须是HTTPS,所以给接口安装了SSL,第一天测试都正常.第二天早上再使用时页面无响应. 抓包发现是后端接口抛出: n ...

  6. 在Windows7上如何找到Cookie

    摘要 出于兴趣爱好,前一阵子做了一个网页,网页中需要用到Cookie,但是,根据书上的说明,并没有找打教材中所说的Cookie的位置,本文就主要介绍在计算机(Win7)中Cookie的存放位置,同样适 ...

  7. BodeAbp服务端介绍

    BodeAbp服务端只提供api,绝大部分api通过abp的动态WebApi机制提供,原理可以参考这篇文章:http://www.cnblogs.com/1zhk/p/5418694.html 与业务 ...

  8. Java中clone的写法

    Cloneable这个接口设计得十分奇葩,不符合正常人的使用习惯,然而用这个接口的人很多也很有必要,所以还是有必要了解一下这套扭曲的机制.以下内容来自于对Effective Java ed 2. it ...

  9. React.js 入门与实战之开发适配PC端及移动端新闻头条平台课程上线了

    原文发表于我的技术博客 我在慕课网的「React.js 入门与实战之开发适配PC端及移动端新闻头条平台」课程已经上线了,文章中是目前整个课程的大纲,以后此课程还会保持持续更新,此大纲文档也会保持更新, ...

  10. NB-IOT_BC95_B5常用AT指令集

    .AT+<cmd>=? 测试命令,用于向模块询问支持的设置项目. .AT+<cmd>? 读取命令,用于让模块上报某个命令代表的设置项当前的值. .AT+<cmd>= ...