A10759 | Alyona and mex
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $l_{i}$ and $r_{i}$ , and its elements are $a[l_{i}],a[l_{i}+1],...,a[r_{i}]$ .
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$ .
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 $l_{i}$ and $r_{i}$ , and its elements are $a[l_{i}],a[l_{i}+1],...,a[r_{i}]$ .
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<=10^{5}$ ).
The next $m$ lines contain information about the subarrays chosen by Alyona. The $i$ -th of these lines contains two integers $l_{i}$ and $r_{i}$ ( $1<=l_{i}<=r_{i}<=n$ ), that describe the subarray $a[l_{i}],a[l_{i}+1],...,a[r_{i}]$ .
The next $m$ lines contain information about the subarrays chosen by Alyona. The $i$ -th of these lines contains two integers $l_{i}$ and $r_{i}$ ( $1<=l_{i}<=r_{i}<=n$ ), that describe the subarray $a[l_{i}],a[l_{i}+1],...,a[r_{i}]$ .
输出格式
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 $10^{9}$ .
It is guaranteed that there is an optimal answer in which all the elements in $a$ are between $0$ and $10^{9}$ .
If there are multiple solutions, print any of them.
In the second line print $n$ integers — the array $a$ . All the elements in $a$ should be between $0$ and $10^{9}$ .
It is guaranteed that there is an optimal answer in which all the elements in $a$ are between $0$ and $10^{9}$ .
If there are multiple solutions, print any of them.
输入输出样例
输入 #1
5 3 1 3 2 5 4 5
输出 #1
2 1 0 2 1 0
输入 #2
4 2 1 4 2 4
输出 #2
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted