Codeforces Round #381 (Div. 2) C. Alyona and mex(模拟)
来源:互联网 发布:英语口语速成软件下载 编辑:程序博客网 时间:2024/05/16 14:51
C. Alyona and mex
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
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.
Examples
input
5 3
1 3
2 5
4 5
output
2
1 0 2 1 0
input
4 2
1 4
2 4
output
3
5 2 0 1
Note
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.
题意:有N个数的序列,接着给出M组(left,right),对于每一组(left,right)为下标对应的序列区间,mex为不在该区间的最小非负整数。这道这样一组N个数的序列,使得M个mex值中的最小值最大。
乱搞,这场CF全都是乱搞
#include<stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;int main(){ int N,M; scanf("%d%d",&N,&M); int min_mex=N; while(M--) { int left,right; scanf("%d%d",&left,&right); min_mex=min(min_mex,right-left+1); } printf("%d\n",min_mex); for(int i=1;i<=N;i++) printf("%d ",i%min_mex); printf("\n"); return 0;}
- 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
- 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) Alyona and mex
- Codeforces Round #381C. 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. 1) A. Alyona and mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex
- Codeforces Round #358 (Div. 2) B. Alyona and Mex【水题】
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
- postman 发送带cookie的请求
- Tensorflow深度学习入门——下载和读取MNIST数据
- 斐波那契数列
- Windows(64bit)下Python2.7环境安装paramiko模块
- 欢迎使用CSDN-markdown编辑器
- Codeforces Round #381 (Div. 2) C. Alyona and mex(模拟)
- Android设置背景透明的一些问题
- MySQL 及 SQL 注入
- 反卷积与语义分割
- Android-使用Android Studio实现第三方QQ登录
- Ember.js学习笔记
- ICE的安装以及环境变量配置
- visual studio运行时库MT、MTd、MD、MDd
- Openwrt的uci操作