问题 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. Maven修改默认仓库为阿里云仓库

    Maven 仓库默认在国外, 国内使用难免很慢,我们可以更换为阿里云的仓库. 第一步:修改 maven 根目录下的 conf 文件夹中的 setting.xml 文件,在 mirrors 节点上,添加 ...

  2. 最优化理论-Simplex线性规划

     Sorry,各位,现在这里面啥也没,之所以开这篇文章,是防止以后用得到:现在研究这些,总感觉有些不合适,本人还不到那个层次:如果之后有机会继续研究simplex-线性规划问题,再回来参考下面的链接进 ...

  3. spring-eureka 源码解读----作为集群的eureka怎么样实现不做二次传播

    在平时工作中,eureka作为一个集群时候,我们会配置多个peer ,假设当前有服务器eureka-A,eureka-B,eureka-C. 如果Eureka A的peer指向了B, B的peer指向 ...

  4. Vue多环境配置

    Vue多环境配置 大家都知道,使用vue-cli脚手架生成的Vue项目只有开发环境和生产环境,然而在实际开发中,用到的不止这些环境,还包括测试环境,准生产环境等等.所以需要自己添加没有的环境. 以测试 ...

  5. jsp学习与提高(五)——JSP 异常处理

    JSP 异常处理 当编写JSP程序的时候,程序员可能会遗漏一些BUG,这些BUG可能会出现在程序的任何地方.JSP代码中通常有以下几类异常: 检查型异常:检查型异常就是一个典型的用户错误或者一个程序员 ...

  6. css各种水平垂直居中

    css各种水平垂直居中,网上查了一下,总结以下几种 line-height垂直居中 缺点,仅限于单行文字 .item{ text-align: center; height: 100px; line- ...

  7. 洛谷P4238【模板】多项式求逆

    洛谷P4238 多项式求逆:http://blog.miskcoo.com/2015/05/polynomial-inverse 注意:直接在点值表达下做$B(x) \equiv 2B'(x) - A ...

  8. 如果查询的结果少,可以把查询结果当子集,再查另一张表,比join的速度快得多得多

    ) as qty from riv_print_history_l phl JOIN tab_user_profile up on up.UP_USER_ID = phl.PHL_PRINT_USER ...

  9. 前端html与css学习笔记总结篇(超详细)

    第一部分 HTML 第一章 职业规划和前景 职业方向规划定位: web前端开发工程师 web网站架构师 自己创业 转岗管理或其他 web前端开发的前景展望: 未来IT行业企业需求最多的人才 结合最新的 ...

  10. EF+mvc+mysql

    这个真是一个大坑啊.TM折腾了一下午终于弄好了.赶紧记录下来分享给大家,免得有和我一样一直配置不成功的又折腾半天….1.安装MySQL for Visual Studio这个直接在mysql官网下载并 ...