Distinct Values(贪心)
问题 D: Distinct Values
时间限制: 1 Sec 内存限制: 128 MB
提交: 13 解决: 5
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Chiaki would like to find a lexicographically minimal array which meets the facts.
输入
The first line contains two integers n and m (1≤n,m≤105) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (1≤li≤ri≤n).
It is guaranteed that neither the sum of all n nor the sum of all m exceeds 106.
输出
样例输入
3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
样例输出
1 2
1 2 1 2
1 2 3 1 1
思路:把一个区间的端点中值较大的一个放在前面,向后压倒! 详见代码:
AC代码:
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
priority_queue<int,vector<int>,greater<int> > store;
int t,n,m,l,r,a[];
int main()
{
scanf("%d",&t);
while(t--)
{
ans.clear();
while(!store.empty()) store.pop();
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
a[i]=i;
store.push(i);
}
while(m--)
{
scanf("%d %d",&l,&r);
a[l]=max(a[l],r);
}
int cnt=,now=;
for(int i=;i<=n;i++)
{
if(a[i]<now) continue;
while(now>a[cnt+] && cnt+<now)
{
store.push(ans[cnt]);
cnt++;
}
while(now<=a[i])
{
ans.push_back(store.top());
store.pop();
now++;
}
}
for(int i=;i<ans.size();i++)
{
if(i==) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}
Distinct Values(贪心)的更多相关文章
- 2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Ot ...
- hdu 6301 Distinct Values (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu多校1004 Distinct Values
Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...
- hdu 6301 Distinct Values (2018 Multi-University Training Contest 1 1004)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 多校对抗赛 D Distinct Values
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 6301 Distinct Values (思维+set)
hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- hdu 6301 Distinct Values(贪心)题解
题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...
随机推荐
- 从扫码支付想到的超级APP主宰一切,数据!数据!还是数据!
前言 做室内定位的人其实内心都明白:基于指纹方法的移动端定位,无论paper每年出来多少,距离真正的大规模应用的距离还有多么遥远.指纹采集,指纹更新,似乎在生产实践上就是不可能的难题.所有还在基于人工 ...
- 3dmax 法线重置
从一个模型分离部位时,分离出的部分,面法线发生了混乱,左边原始模型,右边分离后 重置法线方法 对模型(比如对分离出的下半身)添加 EditoNormal修改器 选中模型部位 添加Edit Normal ...
- AndroidStudio常用快捷键
Alt+Insert:查找override函数 Alt+Enter:自动引包
- Pycharm 设置TextStyle
之前在脚本中选择了一个字符串, PyCharm会"高亮"所有相同的字符串, 但是我不满意这个"高亮"的颜色,因为和背景色太相似了,所以需要做一下操作,修改这个& ...
- EXP-00000: Message 0 not found; No message file for product=RDBMS, facility=EXP问题的解决方案
EXP-00000: Message 0 not found; No message file for product=RDBMS, facility=EXP 最近在服务器上准备做一个批处理,定时备份 ...
- mysql错误之errorcode 1215问题
1.此类问题出现时我们往往会迫不及待的去百度,但是问题偶尔也不是我们想的那样,比如我本次犯下的错误如下: 上图是我给表添加外键约束的时候的sql.下图是我建的表,问题出哪里了?原来是我的数据库根本没有 ...
- Linux下处理^M字符
很多时候windows环境中编辑过的文件,在Linux下经常会出现^M字符,可以通过以下方式处理该字符. vim命令打开文件,然后在vim命令模式下输入以下内容: :%s/^M//g特别注意:注意^M ...
- python所有的魔术方法
据说,Python 的对象天生拥有一些神奇的方法,它们总被双下划线所包围,他们是面向对象的 Python 的一切. 他们是可以给你的类增加魔力的特殊方法,如果你的对象实现(重载)了这些方法中的某一个, ...
- SSIS连接-左外连接
应用场景: 当有多个数据源时,可能是在不同的数据库,或者是一个数据源来自数据库,另一个来自excel文件,想要把他们合并,像sql的左外联接时,应用到 源1: select 'A01' GoodsNo ...
- Swagger 2.0 集成配置
传统的API文档编写存在以下几个痛点: 对API文档进行更新的时候,需要通知前端开发人员,导致文档更新交流不及时: API接口返回信息不明确 大公司中肯定会有专门文档服务器对接口文档进行更新. 缺乏在 ...