问题 D: Distinct Values

时间限制: 1 Sec  内存限制: 128 MB
提交: 13  解决: 5
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Chiaki has an array of n positive integers. You are told some facts about the array: for every two elements ai and aj in the subarray al..r (l≤i<j≤r), ai≠aj holds.
Chiaki would like to find a lexicographically minimal array which meets the facts.

输入

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

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.

输出

For each test case, output n integers denoting the lexicographically minimal array. Integers should be separated by a single space, and no extra spaces are allowed at the end of lines.

样例输入

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(贪心)的更多相关文章

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

  2. hdu 6301 Distinct Values (贪心)

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. HDU6301 Distinct Values (多校第一场1004) (贪心)

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  4. 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. hdu多校1004 Distinct Values

    Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...

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

  7. HDU 多校对抗赛 D Distinct Values

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  8. hdu 6301 Distinct Values (思维+set)

    hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...

  9. hdu 6301 Distinct Values(贪心)题解

    题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...

随机推荐

  1. MVC4 razor与aspx的区别以及用法

    Model要重,Controller要轻,View要够笨,mvc不希望在开发view时还需要判断过多的与view无关的技术,所以要尽可能的保持view逻辑简单.(以下中有出现代码的地方用了什么尖括号百 ...

  2. FZU 2219【贪心】

    思路: 因为工人造完一个房子就死了,所以如果m<n则还需要n-m个工人. 最优的方案应该是耗时长的房子应该尽快建,而且最优的是越多的房子在建越好,也就是如果当前人数不到n,只派一个人去分裂. 解 ...

  3. 前端需要了解的http知识

    一.五层协议1. OSI(Open System Interconnection 开放式系统互联)七层协议 1)应用层 2)表示层 3)会话层 4)传输层 5)网络层 6)数据链接层 7)物理层2. ...

  4. Solr 6.7学习笔记(05)-- highlighter

    搜索结果高亮显示是搜索引擎中的常用功能,在Solr中,我们可以如下配置: <requestHandler name="/select" class="solr.Se ...

  5. openinstall的免费服务对App推广有哪些帮助?

    想在微信中下载 App,需要“点击右上角打开浏览器”,太麻烦: 想深入查看微信分享内容,需要手动打开 App 搜索,不方便: 想给 App 做推广,Android 需要多个渠道人工打包,效率低: .. ...

  6. jar包冲突问题

    这两天在启动一个新项目的时候,项目一直启动不了,报StackOverFlow; java.util.concurrent.ExecutionException: java.lang.StackOver ...

  7. Net Core2.0下使用Dapper

    Net Core2.0下使用Dapper 今天成功把.Net Framework下使用Dapper进行封装的ORM成功迁移到.Net Core 2.0上,在迁移的过程中也遇到一些很有意思的问题,值得和 ...

  8. Spring创建对象的几种方法

    一.通过构造器 无参构造器 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  9. Cube中维度排序-通过在数据仓库增加列来实现排序

    数据仓库增加排序列: 维度设置: 正确结果:

  10. spirngmvc整合mybatis

    一.建立一张简单的User表 CREATE TABLE `users` (`id` int(20) NOT NULL AUTO_INCREMENT,`name` varchar(20) NOT NUL ...