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
  1. 5 3
    1 3
    2 5
    4 5
output
  1. 2
    1 0 2 1 0
input
  1. 4 2
    1 4
    2 4
output
  1. 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.

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

代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <cstring>
  8. #include <string>
  9. #include <set>
  10. #include <map>
  11. #include <unordered_map>
  12. #include <queue>
  13. #include <stack>
  14. #include <vector>
  15. #include <list>
  16. #define rep(i,m,n) for(i=m;i<=n;i++)
  17. #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
  18. #define mod 1000000007
  19. #define inf 0x3f3f3f3f
  20. #define vi vector<int>
  21. #define pb push_back
  22. #define mp make_pair
  23. #define fi first
  24. #define se second
  25. #define ll long long
  26. #define pi acos(-1.0)
  27. #define pii pair<int,int>
  28. #define Lson L, mid, ls[rt]
  29. #define Rson mid+1, R, rs[rt]
  30. #define sys system("pause")
  31. #define intxt freopen("in.txt","r",stdin)
  32. const int maxn=1e5+;
  33. using namespace std;
  34. int gcd(int p,int q){return q==?p:gcd(q,p%q);}
  35. ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
  36. inline ll read()
  37. {
  38. ll x=;int f=;char ch=getchar();
  39. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  40. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  41. return x*f;
  42. }
  43. int n,m,k,t,ans;
  44. int main()
  45. {
  46. int i,j;
  47. ans=1e9;
  48. scanf("%d%d",&n,&m);
  49. rep(i,,m)scanf("%d%d",&j,&k),ans=min(ans,k-j+);
  50. printf("%d\n",ans);
  51. rep(i,,n)
  52. {
  53. printf("%d ",(i-)%ans);
  54. }
  55. //system("Pause");
  56. return ;
  57. }

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

    http://abowman.com/google-modules/ball-clock/

  2. 关于 div随网页居中问题

    可以先在外部设置个 宽高 小于浏览器的 div 内容再根据 最外层 定位 这个代码是 左右居中的 <div style=" width:300px; height:300px; mar ...

  3. maven中添加proguard来混淆代码

    只要下回插件并添加相应的配置文件即可.本文仅是做下相关记录 1.修改pom.xml添加插件 <plugin> <groupId>com.pyx4me</groupId&g ...

  4. rune is alias of int32

    I think chendesheng's quote gets at the root cause best: Go uses a lot of signed values, not just fo ...

  5. 从安装.net Core 到helloWord(Mac上)

    最近听说微软 正式发不了.netCore 1.0 于是就安装了 并安装了vs Code 用于编写一些.net程序 一. .netCore的安装: 首先需要通过brew安装openssl(相信homeB ...

  6. HTML canvas图像裁剪

    canvas drawImage方法的图像裁剪理解可能会比较耗时,记录一下,以便供人翻阅! context.drawImage(img,sx,sy,swidth,sheight,x,y,width,h ...

  7. mycat 概述

    从开始接触mycat,到现在为止也有三个多月的时间了,目前在测试环境中已经初步应用!大概可以总结一下了 mycat是一个数据库中间件,也可以理解为是数据库代理.在架构体系中是位于数据库和应用层之间的一 ...

  8. Location-aware Associated Data Placement for Geo-distributed Data-intensive Applications--INFOCOM 2015

    [标题] [作者] [来源] [对本文评价] [why] 存在的问题 [how] [不足] assumption future work [相关方法或论文] [重点提示] [其它]

  9. JAVA类与对象(课堂总结)

    一:"=="的不同含义 当"=="施加于原始数据类型变量时,是比较变量所保存的数据是否相等当"=="施加于引用类型变量时,是比较这两个变量是 ...

  10. iOS蓝牙开发

    蓝牙常见名称和缩写 MFI ======= make for ipad ,iphone, itouch 专们为苹果设备制作的设备 BLE ==== buletouch low energy,蓝牙4.0 ...