Codeforces #381 C. Alyona and mex
来源:互联网 发布:mac mobi convert 编辑:程序博客网 时间:2024/05/22 14:27
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 31 32 54 5
21 0 2 1 0
4 21 42 4
35 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.
题目大意: 重要是理解mex的意思,我做的时候没有找到mex 的解释,一直懵逼,后来第二天才发现里面有一句,意思是:mex是这串子集中没有出现过的非负整数的最小值,现在n个元素的未知数组,给你提供了m个区间li到ri,每个区间找到一个mex值,然后比较,找出这么多区间中最小的那个mex值,现在想让我们尽可能使最终得到的mex值尽可能的大,让我们输出最后得出尽可能大的mex的值,然后再随便输出任意一组正确的数组。
题目分析:这道题读懂之后,首先要解决的是最终得到的最大的mex值,因为给定的区间,所以我们可以通过给定的区间进行判断,因为我们要使得到的最小值最大化,所以我们应该找到最小的区间长度,而这个区间长度就是最大的mex值。接下来是任意输出一个满足条件的数组。这个数组的构造刚开始想不到,但是后来想想,就是用i从0到n去mod x(mex)的值,0 1 ...x-1 0 1 ...x-1。即使是最小的区间,也肯定能被这个从0到x-1覆盖,因为本来就是基于这个最小区间才得到的值。
#include <cstdio>#include <cstring>#include <map>#include <algorithm>using namespace std;const int maxn = 100005;int a[maxn],b[maxn];int main(){int n, m;while(~(scanf("%d%d",&n,&m))){int minm=100000;int u,v;while(m--){scanf("%d%d",&u,&v);minm=min(abs(u-v)+1,minm);}printf("%d\n",minm);for(int i=0;i<n-1;i++){printf("%d ",i%minm);} printf("%d\n",(n-1)%minm);}return 0;}
- Codeforces Round #381C. Alyona and mex
- Codeforces #381 C. Alyona and mex
- Codeforces Round #381 (Div. 2)C - Alyona and mex
- Codeforces Round #381 (Div. 2) C. Alyona and mex
- Codeforces Round #381 (Div. 2)C. Alyona and mex
- Codeforces Round #381 (Div. 2)-C. Alyona and mex
- 【39.66%】【codeforces 740C】Alyona and mex
- CodeForces 740C - Alyona and mex(思维)
- 740C.Alyona and mex codeforces
- CodeForces 740C Alyona and mex 简单构造题
- C - Alyona and Mex CF682B
- Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)
- Codeforces#381(Div. 2) C. Alyona and mex【思维】好题~
- Codeforces Round #381 (Div. 2) C. Alyona and mex(模拟)
- Codeforces Round #381 (Div. 2)C. Alyona and mex(构造题,好题)
- Codeforces Round #381 (Div. 2) C. Alyona and mex 贪心+构造
- Codeforces Round #381 (Div. 2) C. Alyona and mex(思维)
- Codeforces Round #381 (Div. 2) C Alyona and mex (构造)
- Android 数据库升级完整解决方案
- asp.net 上传图片的限制图片的大小
- html网页获取php网页数据等知识记录
- Activity继承AppCompatActivity导致的TitleBar无法去除
- Java并发框架(Concurrency)
- Codeforces #381 C. Alyona and mex
- 最近的一些琐事
- 递归算法-求最大公约数-java实现
- 用Jersey+spring+hibernate构建RESTful服务
- easyui tree带checkbox实现单选
- 安卓布局适配的另一种姿势
- IOS导航tabbar 自定义图片显示
- 不同APP通过SharedPreferences传递数据(共享数据)
- 十几年的技术人生,未来怎么走!