CF739A Alyona and mex 题解
前置知识
解法
从贪心的角度分析,最小的 \(\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 题解的更多相关文章
- 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 ...
- 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 ...
- CodeForces 682B Alyona and Mex (排序+离散化)
Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...
- 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 ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- 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 ...
- Alyona and mex
Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 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 ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CF | Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...
随机推荐
- 例2.6 设计一个高效的算法,从顺序表L中删除所有值为x的元素,要求时间复杂度为0(n)空间复杂度为0(1)。
1.题目 例2.6 设计一个高效的算法,从顺序表L中删除所有值为x的元素,要求时间复杂度为0(n)空间复杂度为0(1). 2.算法思想 3.代码 void DeleteX(SeqList LA, Se ...
- Shell-全局变量-export
- [转帖]配置cri-docker使kubernetes1.24以docker作为运行时
从kubernetes 1.24开始,dockershim已经从kubelet中移除,但因为历史问题docker却不支持kubernetes主推的CRI(容器运行时接口)标准,所以docker不能再作 ...
- [转帖]【性能】大页内存 (HugePages)在通用程序优化中的应用
目录 1. 背景 2. 基于指纹的音乐检索简介 3. 原理 4. 小页的困境 5. 大页内存的配置和使用 6. 大页内存的优化效果 7. 大页内存的使用场景 8. 总结 LD_PRELOAD用法 原文 ...
- [转帖]Jmeter学习笔记(二十一)——Concurrency Thread Group阶梯式加压测试
https://www.cnblogs.com/pachongshangdexuebi/p/11739064.html 一.先安装jmeter的插件管理工具 1.下载地址:jmeter-plugins ...
- 阿里的AIGC数据库工具: Chat2DB的学习与使用
阿里的AIGC数据库工具: Chat2DB的学习与使用 背景 今天陪家中老人去完医院后, 继续回来学习时发现 阿里巴巴的 chat2DB已经发布的 2.0.1的版本. 想着下载下来试试. 主要也是备忘 ...
- RabbitMQ 测试环境的简单创建于使用 permission vhost 以及 权限简单设置
之前用docker运行起来 rabbitmq的容器了 但是今天发现有问题. 简单沟通了下 需要进行处理. 方法主要是如下 1. 运行容器: docker run --name rabbitmq -ti ...
- rfc7230 Message Syntax and Routing
rfc7230 目录 rfc7230 2 Architecture 2.6 Protocol Versioning 3 Message Format 3.1 Start Line 3.1.1 Requ ...
- 我们开源了一个 Ant Design 的单元测试工具库
我们是袋鼠云数栈 UED 团队,致力于打造优秀的一站式数据中台产品.我们始终保持工匠精神,探索前端道路,为社区积累并传播经验价值. 本文作者:佳岚 欢迎大家点一个小小的 Star ant-design ...
- 全球首个面向遥感任务设计的亿级视觉Transformer大模型
作者:京东探索研究院 深度学习在很大程度上影响了遥感影像分析领域的研究.然而,大多数现有的遥感深度模型都是用ImageNet预训练权重初始化的,其中自然图像不可避免地与航拍图像相比存在较大的域差距,这 ...