题目传送门

前置知识

贪心 | 构造

解法

从贪心的角度分析,最小的 \(\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. 传说中 PUE 预测精度高达 0.005 的工作

    杨震, 赵静洲, 林依挺 等. 数据中心 PUE 能效优化的机器学习方法. 系统工程理论与实践, 2022, 42(3): 811-832 省流: 这是 2020 年的论文,用神经网络进行了认真的 P ...

  2. 2023第十四届极客大挑战 — RE WP

    RE方向出自:队友. Shiftjmp 去花后按p然后再反编译 最后flag为SYC{W3lc0me_tO_th3_r3veR5e_w0r1d~} 点击就送的逆向题 gcc 1.s -o 1` 生成e ...

  3. java - 冒泡排序求最值

    public class Bubble3 { public static void main(String[] args) { int[] arr; arr = new int[]{2,3,6,1}; ...

  4. 【Spring 5核心原理】1设计模式

    1.1开闭原则 开闭原则(open-closed principle,OCP)是指一个软件实体(如类,模块和函数)应该对扩展开放,对修改关闭.所谓的开闭,也正是对扩展和修改两个行为的一个原则. 强调用 ...

  5. [转帖]细说:Unicode, UTF-8, UTF-16, UTF-32, UCS-2, UCS-4

    https://www.cnblogs.com/malecrab/p/5300503.html 1. Unicode与ISO 10646 全世界很多个国家都在为自己的文字编码,并且互不想通,不同的语言 ...

  6. [转帖]Spring为啥不推荐使用@Autowired注解?

    https://my.oschina.net/u/5079097/blog/5289666   引言 使用IDEA开发时,同组小伙伴都喜欢用@Autowired注入,代码一片warning,看着很不舒 ...

  7. [转帖]【教程】如何在不同架构打包Docker镜像

    https://docs.qsnctf.com/qsnctf/37674.html 前言 大家在使用Docker的时候经常会遇到一个问题,就是受用机和本级不是同一架构.就比如小编使用的就是新版本的Ma ...

  8. [转帖]Docker资源(CPU/内存/磁盘IO/GPU)限制与分配指南

    https://zhuanlan.zhihu.com/p/417472115 什么是cgroup? cgroups其名称源自控制组群(control groups)的简写,是Linux内核的一个功能, ...

  9. [转帖]JVM 参数

    https://www.cnblogs.com/xiaojiesir/p/15636100.html 我们可以在启动 Java 命令时指定不同的 JVM 参数,让 JVM 调整自己的运行状态和行为,内 ...

  10. Oracle12c(未更新任何补丁) 使用compression=all 参数导出之后导入失败

    1. 最近使用Oracle12c 进行相关的测试工作, 平台linux 和 windows 都有一个问题 备份恢复使用的 compression=all 时导入数据库不管是oracle12c还是 or ...