A. Alyona and mex

题目连接:

http://codeforces.com/contest/739/problem/A

Description

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.

Sample Input

5 3

1 3

2 5

4 5

Sample Output

2

1 0 2 1 0

Hint

题意

给你n个数,然后m个区间,你需要构造n个数,使得这m个区间的mex最小值最大。

题解:

其实只和区间长度有关,你按照0123......0123这样去构造,那个区间总能够包含0到那么多的数的。

代码

#include<bits/stdc++.h>
using namespace std; int n,m;
int main()
{
scanf("%d%d",&n,&m);
int ans = n;
for(int i=1;i<=m;i++){
int l,r;
scanf("%d%d",&l,&r);
ans = min(ans,r-l+1);
}
cout<<ans<<endl;
for(int i=0;i<n;i++){
cout<<i%ans<<" ";
}
cout<<endl;
}

Codeforces Round #381 (Div. 1) A. 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 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 ...

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

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

  4. Codeforces Round #381 (Div. 2) A B C 水 构造

    A. Alyona and copybooks time limit per test 1 second memory limit per test 256 megabytes input stand ...

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

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

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

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

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

随机推荐

  1. 2600: [Ioi2011]ricehubh

    Description 乡间有一条笔直而长的路称为"米道".沿着这条米道上 R 块稻田,每块稻田的坐标均为一个 1 到 L 之间(含 1 和 L)的整数.这些稻田按照坐标以不减的顺 ...

  2. Servlet中使用Log4j2

    因为Servlet常用的版本有两个,即2.5与3.0.要在web application中使用Log4j2,还需要加入log4j-web的jar包.log4j通过web.xml中的context参数l ...

  3. win7连接共享打印机 错误为

    1.  xp局域网共享打印机,本机运行 –>  \\共享电脑ip –> 选择驱动目录 .INF 文件 –> 确认. 直接报错..... 2.  参考方法: 开始——设备和打印机——添 ...

  4. WordPaster-Chrome浏览器控件安装方法

    将WordPaster.crx拖到Chrome扩展面板中安装

  5. Xml序列化UTF-8格式错误

    我需要得到一个类的Xml序列化后的字符串 using (System.IO.MemoryStream mem = new System.IO.MemoryStream()) { XmlTextWrit ...

  6. (二分)Block Towers(cf626)

    http://www.codeforces.com/contest/626/problem/C 题意是有一群小朋友在堆房子,现在有n个小孩每次可以放两个积木,m个小孩,每次可以放3个积木,最后每个小孩 ...

  7. (原创)defparam的应用(Verilog,CPLD/FPGA)

    1.Abstract     在同一个模块被多次例化的时候,改变参数构建不同的硬件实体是一个很好的选择.特别是今天帮一个朋友调试一个比较复杂的逻辑,深有体会.这个也是一个小技巧,回来也查了许多资料,强 ...

  8. PHP访问数据库

    1.原生mysql方式 <?php //最原生态的访问方式,不过SQL注入是个麻烦事 $con = mysql_connect("localhost","root& ...

  9. 一步一步搭建客服系统 (4) 客户列表 - JS($.ajax)调用WCF 遇到的各种坑

    本文以一个生成.获取“客户列表”的demo来介绍如何用js调用wcf,以及遇到的各种问题. 1 创建WCF服务 1.1 定义接口 创建一个接口,指定用json的格式:   [ServiceContra ...

  10. Helios与Katana的区别

    Helios与Katana都是微软开发的基于IIS的OWIN实现. 它们之间的区别很简单:Helios不依赖于ASP.NET Runtime,Katana依赖于ASP.NET Runtime. Hel ...