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 ...
随机推荐
- RBAC在thinkphp中有Auth类 可以很好的实现权限控制
import('ORG.Util.Auth');//加载类库 $auth=new Auth(); if($auth->check('show_button',1)){// 第一个参数是规则名称, ...
- Axure 7.0 正式版 + 汉化包 安装
详情如下: Axure 7.0 正式版终于发布了,现在提供简体中文版给大家使用. Axure 7.0 正式版: 链接: http://pan.baidu.com/s/1kV4OJ47 提取密码: be ...
- 艺术品照片融合到背景墙上效果及DEMO
演示地址: 功能:图片按照角度增加阴影,比较复杂的功能就是当墙面是不规则的时候,贴的艺术品必须按照墙面的角度进行变形处理.
- json---简单入门
1.推荐使用第三种方式JAVABEAN的方式(使用前引入org.json) package day05; import java.util.HashMap; import java.util.Map; ...
- linux使用grep和find查找内容
1,在某个路径下查文件. 在/etc下查找“*.log”的文件 find /etc -name “*.log” 2,扩展,列出某个路径下所有文件,包括子目录. find /etc -name “*” ...
- c++中resize函数怎么用
resize(),设置大小(size);reserve(),设置容量(capacity);size()是分配容器的内存大小,而capacity()只是设置容器容量大小,但并没有真正分配内存.打个比方: ...
- Google V8编程详解(四)Context
http://blog.csdn.net/feiyinzilgd/article/details/8266780 上一章,比较略提了下V8的Context.本章将详细的讲解下Context的概念以及用 ...
- thinkphp nginx php-fpm url rewrite 导致 404 错误
## thinkphp nginx php-fpm url rewrite 导致 404 错误 之前thinkphp的系统部署在apache上,考虑到在并发性能nginx比apache强悍得多,所以在 ...
- Unix调试工具dbx使用方法
dbx 命令 用途 提供了一个调试和运行程序的环境. 语法 dbx [ -a ProcessID ] [ -c CommandFile ] [ -d NestingDepth ] [ -I Dire ...
- js获取及判断按键的方法
js 里面的键盘事件经常用到,所以收集了键盘事件对应的键码来分享下: keyCode 8 = BackSpace BackSpace keyCode 9 = Tab Tab keyCode 12 = ...