题目传送门

前置知识

贪心 | 构造

解法

从贪心的角度分析,最小的 \(\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. Multi-Master APB Interconnect

    APB总线并不是只有一个master(AHB2APB Bridge),可以通过设计支持多个APB Master,只是比较复杂 Lattice 实现了一款Multi-Master Interconnec ...

  2. SQLServer 执行计划的简单学习和与类型转换的影响

    SQLServer 执行计划的简单学习和与类型转换的影响 背景 最近一直在看SQLServer数据库 索引.存储.还有profiler的使用 并且用到了 deadlock graph 但是感觉还是不太 ...

  3. [转帖]编译安装goofys挂载Scaleway免费75G对象存储

    日常•2022年5月29日   goofys编译 goofys是一个开源的使用Go编写的s3存储桶挂载工具,主打高性能.由于使用Go编写,没有用到什么特别的依赖,自己编译也很容易.截止2022.5.2 ...

  4. [转帖]Jmeter创建数据库(JDBC)测试-4

    上一章节讲述如何建立HTTP请求测试,本章节将介绍使用MySQL数据库驱动程序进行JDBC测试.要使用该驱动程序,必须将其包含的.jar文件(例如mysql-connector-java-XXX-bi ...

  5. buildkit 官网 service 资料

    [Unit]   Description=BuildKit   Requires=buildkit.socket   After=buildkit.socket   Documentation=htt ...

  6. 不同信创服务器Redis7.0.5性能表现总结

    不同信创服务器Redis7.0.5性能表现总结 背景以及基础约定 随着美帝2022.10收紧EAR规定的硬件出口规定 信创事业迎来了一波新的高潮. 最近不仅仅要求国产化的硬件. 更要求国产化的OS,以 ...

  7. 01uni-app的创建运行在不同端上的配置 以及tarBar的配置

    uni-app的创建### 01==>创建uni-app的项目非常简单.不需要注意什么注意点哈!! 创建项目的时候 可以参考官网 https://uniapp.dcloud.io/quickst ...

  8. 正则表达式match方法和search方法

    正则表达式, //match() 方法可在字符串内检索指定的值 找到返回相关数据,找不到返回null var part = /Box/ig; var str = "this is box,i ...

  9. 2021美亚杯团队赛write up

    个人赛与团队赛下载文件解压密码:MeiyaCup2021 加密容器解密密码: uR%{)Y'Qz-n3oGU`ZJo@(1ntxp8U1+bW;JlZH^I4%0rxf;[N+eQ)Lolrw& ...

  10. 系统Hosts文件原理和应用

    Hosts的概念 Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库",当用户在浏览器中输入一个需要 ...