Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
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 构造的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #381 (Div. 2) C. Alyona and mex(无语)
题目链接 http://codeforces.com/contest/740/problem/C 题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- webview 实现滑动前进后退功能
实现该功能大家一定会想到在OnTouchListener里实现 webview.setOnTouchListener(new OnTouchListener() { @Override public ...
- innobackupex使用实践
先介绍一下环境: MySQL:5.6.19 安装路径:/u01/mysql 数据文件:/u01/mysql/data 备份源:/u02/backup 我是异机恢复,和本机操作一样. 一. 全量备份 步 ...
- FastDFS基本结构(转)
0.简介 FastDFS是基于互联网应用的开源分布式文件系统,主要用于大中型网站存储资源文件,如图片.文档.音频.视频等.FastDFS采用类似GFS的架构,用纯C语言实现,支持Linux.FreeB ...
- [转]oracle 10g数据泵之impdp-同时导入多个文件
要了解impdp,请先了解导出,我之前作过导出的笔记:oracle 10g数据泵之expdp.这两个笔记也许只对程序员有用,通常用于把正式区的数据导入到测试区,对数据库管理员也许帮助不大,他们使用这些 ...
- Hadoop-1.2.1 安装步骤小结(ubuntu)
1.安装ubuntu系统 如果不使用云服务器,可以使用虚拟机WmWare安装,具体安装步骤这里就不讲了,ubuntu系统下载地址:http://www.ubuntu.com/download/desk ...
- 大熊君说说JS与设计模式之(门面模式Facade)迪米特法则的救赎篇------(监狱的故事)
一,总体概要 1,笔者浅谈 说起“门面”这个设计模式其实不论新老程序猿都是在无意中就已经运用到此模式了,就像我们美丽的JS程序员一样不经意就使用了闭包处理问题, function Employee(n ...
- ASP.NET 5中的静态文件处理
ASP.NET 5 与之前的 ASP.NET 相比,有着翻天覆地的变化.了解与熟悉它需要一个过程,而我选择的了解方式是一步一步从无而有手写一个简单的 ASP.NET 5 程序,然后根据遇到的问题进行学 ...
- 通过Anuglar Material串串学客户端开发 - NodeJS模块机制之Module.Exports
module.exports 前文讲到在Angular Material的第二个编译文件docs/gulpfile.js中却看到了一个奇怪的东西module.exports那么module.expor ...
- [51单片机] EEPROM 24c02 [I2C代码封装-保存实现流水灯]
这里把EEPROM 24c02封装起来,今后可以直接调用,其连线方式为:SDA-P2.1;SCL-P2.0;WP-VCC >_<:i2c.c /*--------------------- ...
- crossplatform---Nodejs in Visual Studio Code 09.企业网与CNPM
1.开始 CNPM : https://npm.taobao.org/ 2.企业网HTTP代理上网 平时办公在一个大企业网(10.*.*.*)中,使用HTTP代理上网,发现npm命令无法执行. 解决方 ...