题目传送门

前置知识

贪心 | 构造

解法

从贪心的角度分析,最小的 \(\operatorname{mex}\) 仅会与长度最小的区间有关;另外为使得 \(\operatorname{mex}\) 最大,当 \(\operatorname{mex}\) 等于区间长度的时候即为所求。记 \(ans\) 表示此时得到的答案。

构造序列时,长度最小的区间一定包含 \([0,ans-1]\) 的所有数。对于其他的区间,一定包含一个长度为 \(ans\) 的区间,使得这个区间也包含 \([0,ans-1]\) 的所有数,剩余的部分长度如果小于 \(ans\),可以任意构造;否则,构造方法同上。于是,我们得到了一种可行的构造:将 \([0,ans-1]\) 循环输出即可。

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sort stable_sort
#define endl '\n'
int main()
{
int n,m,l,r,i,len=0x7f7f7f7f;
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>l>>r;
len=min(len,r-l+1);
}
cout<<len<<endl;
for(i=1;i<=n;i++)
{
cout<<i%len<<" ";
}
return 0;
}

CF739A Alyona and mex 题解的更多相关文章

  1. 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 ...

  2. 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 ...

  3. CodeForces 682B Alyona and Mex (排序+离散化)

    Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...

  4. 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 ...

  5. Codeforces 740C. Alyona and mex 思路模拟

    C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  6. 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 ...

  7. Alyona and mex

    Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  8. Codeforces Round #381 (Div. 2)C Alyona and mex

    Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...

  9. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. CF | Alyona and Mex

    Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...

随机推荐

  1. Could not get a resource from the pool 异常定位和解决

    最近在服务中经常看到以下错误,进行下定位和问题解决分析: 2023-12-08 00:10:58.248 WARN [terra-sr-server,a9006fd27ccb81d0,a9006fd2 ...

  2. Hystrix 源码解读

    转载请注明出处: 1.引入依赖: <dependency> <groupId>org.springframework.cloud</groupId> <art ...

  3. 这一次,弄明白JS中的文件相关(二):HTTP请求头和响应头

    (一)前置知识 开始前,我们先来复习一下HTTP的基础知识. HTTP请求分为:请求行.请求头.空行.请求体(也叫正文.请求实体.请求主体). HTTP响应分为:状态行(也叫响应行).响应头.空行.响 ...

  4. [转帖]k8s集群部署工具kubeadm详解

    https://zhuanlan.zhihu.com/p/670125857 kubeadm是快捷创建Kubernetes集群的最佳实践工具,我们只需用kubeadm init 和 kubeadm j ...

  5. [转帖]深入理解mysql-第六章 mysql存储引擎InnoDB的索引-B+树索引

    一.引入索引 在没有索引的情况下,不论是根据主键列或者其他列的值进行查找,由于我们并不能快速的定位到记录所在的页,所以只能从第一个页沿着双向链表一直往下找,因为要遍历所有的数据页,时间复杂度就是O(n ...

  6. MySQL控制权限

    编写顺序和执行顺序是不一样的 编写顺序: SELECT 字段列表 FROM 表名列表 WHERE 条件列表 GROUP BY 分组字段列表 HAVING 分组后条件列表 ORDER BY 排序字段列表 ...

  7. element-plus 按需引入将英文组件修改为中文

    element-plus 默认是英文组件:如下图 将它设置为中文组件 app.vue文件 <template> <el-config-provider :locale="l ...

  8. 用webpack给js添加上版本号

    在网上查找了很多的资料. 都没有好的资源 因为我现在在项目是vuecli3.0 需要自己去创建文件 在项目的根目录下,创建一个文件vue.config.js 然后在该文件下写 const webpac ...

  9. Typora 1.6.7永久激活

    介绍Typora介绍 具体看上面的我就不多介绍了 接下来我们开始教程 需要的文件 Typora安装包 破解补丁包 安装包下载 破解补丁下载 接下来我们全部下载后获得一个安装包一个补丁 安装包直接安装就 ...

  10. 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取)、文本分类等

    文本抽取任务Label Studio使用指南 1.基于Label studio的训练数据标注指南:信息抽取(实体关系抽取).文本分类等 2.基于Label studio的训练数据标注指南:(智能文档) ...