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.

分析:贪心,分析可知答案为最小区间长度,然后数组循环放就行;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define intxt freopen("in.txt","r",stdin)
const int maxn=1e5+;
using namespace std;
int gcd(int p,int q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,ans;
int main()
{
int i,j;
ans=1e9;
scanf("%d%d",&n,&m);
rep(i,,m)scanf("%d%d",&j,&k),ans=min(ans,k-j+);
printf("%d\n",ans);
rep(i,,n)
{
printf("%d ",(i-)%ans);
}
//system("Pause");
return ;
}

Alyona and mex的更多相关文章

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

  2. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

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

  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 682B Alyona and Mex (排序+离散化)

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

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

  7. CF | Alyona and Mex

    Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...

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

    Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...

  9. B - Alyona and Mex

    Description Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one oper ...

随机推荐

  1. MFC 刷新失效的Picture控件

    问题描述:如在摄像头显示时,关闭摄像头,此时Picture控件仍然显示最后一帧图像,需要刷新掉,还原Picture控件.或者重复显示两张不同大小的图片时,第二张背景有第一张图片残留. 解决方法1:(最 ...

  2. 如何通过subId来获取phoneId?

    androidL中使用一张数据表来保存sim卡信息:telephony.db中有一张记录SIM卡信息的表,siminfo: CREATE TABLE siminfo(_id INTEGER PRIMA ...

  3. delphi 快捷键大全

    ************************* 1.功能键 2.组合键 3.其他快捷键 4.补充 5.补充1(带分类) 6.补充2 --Edit by 2013.1.14 ************ ...

  4. suricata抓包方式之一AF_PACKET

    suricata抓包方式之一AF_PACKET 噜拯渡 睦坚削 曜纡宄 式犒藿氆 咬焚桤φ 要蒯钮 喃俚夼 币噎嶂颐 话千叶舞就后悔了怎么想都容易让人引 虻谮м 及葚雏钏 看着表面平静实际 ...

  5. CVE-2015-0057 POC构造 & 利用分析(2015.7)

    CVE-2015-0057 POC构造 & 利用分析 主要内容: 构造POC 利用思路 0x00 初探 从这篇文章可以获知: 1.问题出在 win32k!xxxEnableWndSBArrow ...

  6. C++编程技巧(长期更新)

    1.数组使用 int* p = new int[5](); // 数组新建并全部初始化为0 等价于: int* p; p = new int[5](); int* q = new int[5];    ...

  7. EditText文本中用正则匹配是否包含数字,及判断文本只能是纯汉字或纯字母

    遇到判断EditText中文本,是否为制定格式 EditText et; Button btn; @Override protected void onCreate(Bundle savedInsta ...

  8. myeclipse6.0安装svn插件

    myeclipse6.0安装svn插件 转载地址:http://www.cnblogs.com/danica/archive/2011/07/12/2104323.html myeclipse6.0安 ...

  9. Android Studio Gradle更新的解决办法

    环境: Win7_64旗舰版.Android Studio2.1.1 问题描述: 在打开Android Studio项目的时候,会下载项目对应版本的gradle,由于是国外网站导致更新较慢,该版本是在 ...

  10. 常用的js事件

    onmouseover:鼠标放上去时触发事件 onmouseout:鼠标从上面移开时触发事件 onclick:鼠标单击事件 onfocus:获得焦点 onblur:失去焦点 onchange:下拉菜单 ...