Codeforces 740C. Alyona and mex 思路模拟
2 seconds
256 megabytes
standard input
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.
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].
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.
5 3
1 3
2 5
4 5
2
1 0 2 1 0
4 2
1 4
2 4
3
5 2 0 1
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.
题目链接:http://codeforces.com/contest/740/problem/C
题意:定义mex为一个集合里面没有出现的最小的非负整数,有一个长度为n的集合,m个区间,现在要使得m各区间的最小的mex最大。
思路:最小的mex就是最小的区间长度。因为每个区间0,1,2,3...,才能使得最小的mex最大。当时最小的区间限制了长度,所以最小的mex最大为最小的区间长度x。长度为n的数组只要0,1,2,3,...x-2,x-1循环至n个数。因为每个区间的都是大于等于x的,所以无论怎么取区间都会有0~x-1。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int Max=1e6+;
for(int i=; i<m; i++)
{
int l,r;
scanf("%d%d",&l,&r);
Max=min(Max,r-l+);
}
cout<<Max<<endl;
int sign=;
for(int i=; i<n; i++)
{
cout<<sign<<" ";
sign++;
sign=sign%Max;
}
cout<<endl;
return ;
}
Codeforces 740C. Alyona and mex 思路模拟的更多相关文章
- CodeForces 740C Alyona and mex
构造. 比较骚的构造题.肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$ ...
- CodeForces 682B Alyona and Mex (排序+离散化)
Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...
- CodeForces 682B 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 ...
- 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 ...
- 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 #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 E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Alyona and mex
Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 调用百度地图API出现 error inflating class com.baidu.mapapi.map.mapview
问题如下 本来以为解决了,但后来重新运行了一下,又坏了,然后改成原来的样子,又好了. 结果就是:对不住了各位看官,没找到解决办法,不过经测试有个地方,可能在程序运行时,出现error inflatin ...
- Spring异常抛出触发事务回滚
Spring.EJB的声明式事务默认情况下都是在抛出unchecked exception后才会触发事务的回滚 /** * 如果在spring事务配置中不为切入点(如这里的切入点可以定义成test*) ...
- 填坑*** WARNING L15: MULTIPLE CALL TO SEGMENT
填坑*** WARNING L15: MULTIPLE CALL TO SEGMENT 警告:发生了重入! 解释:在主循环里调用了一个函数,而在中断服务中又一次调用了同样的函数.当主循环运行到该函数中 ...
- js关于页面坐标api
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- mysql命令行导入sql脚本中文变问号问题
之前一直用工具连接mysql虽然小问题不断也都无伤大雅,最近做金融云项目,只能通过服务器的内网访问数据库,也就是说只能在linux下通过命令行访问,在导入中文的时候发现都变成问号了,经过查询资料解决, ...
- C# ASP.NET(配置数据库 sql server 地址的两种形式以及配置信息的获取)
( 1 ) 数据库装在本机,并且采用windows认证模式 <connectionStrings> <add name="SQLConnectionString&qu ...
- 微软ASP.NET技术“乱谈”
微软ASP.NET技术“乱谈” 2014新年了,顺手写的一点文字,主要谈谈我对当前微软ASP.NET技术的看法,比较随意,大伙儿随便看看吧. 1 当前微软Web平台技术全貌 从2002年发布.NET ...
- CSS中浏览器开发商特定的CSS属性
浏览器制造商(像Microsoft.Mozilla等,还有WebKit的后台人员等)通常会为他们的浏览器增加新的功能来测试新的特性, 或者实现一直在考虑但还没有得到标准组织批准的CSS扩展.在这些情况 ...
- TFS Build Definition And Auto Deploy
一台build machine上一般只有一个build service[对应一个build controller]来serve一个team project collection,但又workaroun ...
- 【转】HTML转义字符大全
ISO Latin-1字符集: — 制表符Horizontal tab — 换行Line feed — 回车Carriage Return — Space ! ! — 惊叹号Exclamati ...