Codeforces Round #381 (Div. 2)C. Alyona and mex(构造题,好题)

来源:互联网 发布:pageoffice java 编辑:程序博客网 时间:2024/04/30 00:42

C. Alyona and mex
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

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 31 32 54 5
output
21 0 2 1 0
input
4 21 42 4
output
35 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个区间,你需要构造n个数,使得这m个区间的mex最小值最大。

区间的mex是取不在该区间集合中的最小的非负数。


题解:

其实答案只和区间长度有关,区间最短长度就是答案,序列按照0123......0123这样去构造,那个区间总能够包含0到那么多的数的。


#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>using namespace std;#define rep(i,a,n) for (int i=a;i<n;i++)#define per(i,a,n) for (int i=n-1;i>=a;i--)#define pb push_back#define mp make_pair#define fi first#define se secondtypedef vector<int> VI;typedef long long ll;typedef pair<int,int> PII;const ll mod=1000000007;const int INF=0x3fffffff;int main(){int n,m;cin >> n >> m;int ans=INF;while(m--){int l,r;cin >> l >> r;ans=min(ans,r-l+1);}int cnt=0;cout << ans << endl;rep(i,1,n+1){printf("%d ",cnt);cnt++;cnt%=ans;}return 0;}

0 0