hdu 6301
Distinct Values
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3105 Accepted Submission(s): 1000
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.
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <utility>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int N=1e5+;
int num[N],n,m,pre[N];
int t;
set<int>s;
int main()
{
scanf("%d",&t);
int l,r;
//pre[i]: 在i位置放数时必须要考虑到的最左的位置
while(t--)
{ s.clear();
scanf("%d%d",&n,&m);
memset(num,,sizeof(num));
for(int i=;i<=n;i++)
{ pre[i]=i;
s.insert(i);
}
for(int i=;i<m;i++)
{
scanf("%d%d",&l,&r);
pre[r]=min(pre[r],l);
}
for(int i=n-;i>=;i--){//pre[i]<=pre[i+1]
pre[i]=min(pre[i],pre[i+]);//如:pre[i+1]=1,pre[i]=2,那么pre[i]一定=1
}
int begin=;
for(int i=;i<=n;i++){
while(begin<pre[i]){//可以和begin重复
s.insert(num[begin]);//插入新的
begin++;//同时位置不断的右移
}
num[i]=*s.begin();//最小的(s里面都是满足题意的)
s.erase(num[i]);//避免重复。
}
for(int i=;i<=n;i++){
printf("%d%c",num[i],i==n?'\n':' ');
}
}
return ;
}
hdu 6301的更多相关文章
- hdu 6301 Distinct Values (思维+set)
hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- HDU 6301 Distinct Values
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6301 多校contest1 题目大意是有一个长度为N的数组,给出M个"事实",每个 ...
- 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 6301 Distinct Values(贪心)题解
题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...
- hdu 6301 Distinct Values (双指针,水题)
大意: 给定m个区间, 求构造一个长n且字典序最小的序列, 使得每个区间内的数各不相同 求出每个位置为左端点时向右延伸最大距离, 然后双指针, 每次从set中取最小 #include <iost ...
- HDU 6301 (贪心+优先队列)
题目大意: 求一个长度为n的数列, 给出m个区间,这m个区间各自区间内的数不同 题解: 用优先队列来模拟过程 , 解题思路是想到了 , 可是不知道如何实现 , 果然还须继续努力呀 这道题思路是去掉重复 ...
- HDU 6301.Distinct Values-贪心、构造字典序最小的数列 (2018 Multi-University Training Contest 1 1004)
HDU6301.Distinct Values 这个题就是给你区间要求区间内的数都不相同,然后要求是字典序最小,直接贪心走一遍,但是自己写的时候,思路没有错,初始化写挫了... 将区间按左端点小的排序 ...
- hdu 6301 Distinct Values (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 2018 Multi-University Training Contest - Team 1 题解
Solved A HDU 6298 Maximum Multiple Solved B HDU 6299 Balanced Sequence Solved C HDU 6300 Triangle Pa ...
随机推荐
- ML.NET 示例:目录
ML.NET 示例中文版:https://github.com/feiyun0112/machinelearning-samples.zh-cn 英文原版请访问:https://github.com/ ...
- Spring Boot Security配置教程
1.简介 在本文中,我们将了解Spring Boot对spring Security的支持. 简而言之,我们将专注于默认Security配置以及如何在需要时禁用或自定义它. 2.默认Security设 ...
- C#小记
1.背景:用fileinput 上传文件 直接上传文件,但有时会发现,这个不上传文件也是可以携带其他参数的, 如果直接用: uploadFile = context.Request.Files[]; ...
- Vmware 虚拟硬盘 合并多个分割文件
有时,当我们创建虚拟机vmware里面的应用程序,我们可能会选择创建分割的虚拟磁盘中的多个文件2 GB的文件,这是为了提高复制过程,主要用于存储虚拟机文件系统不支持创建更大的文件. 如果我们需要将它转 ...
- [Oracle 视图] ALL_OBJECTS
ALL_OBJECTS ALL_OBJECTS describes all objects accessible to the current user. ALL_OBJECTS描述当前用户的可访问的 ...
- winform ListView创建columnHeader的方法
using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace ...
- WinForm 窗体API移动 API阴影
窗体移动 //窗体移动API [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllI ...
- Android商城开发系列(九)—— 首页频道布局的实现
在上一篇博客当中,我们讲了关于首页轮询广告的实现,接下来讲解一下首页频道布局的实现,如下图所示: 这个布局用的是gridview去完成的,新建一个channel_item,代码如下所示: <?x ...
- windows server 2008 r2 启用 Windows Defender
单击“开始”,指向“管理工具”,然后单击“服务器管理器”. 在“服务器管理器”中,单击“功能”,然后在“服务器管理器”细节窗格中的“功能摘要”下,单击“添加功能”. 此时会启动“添加功能向导”. 在“ ...
- 使用JPA + Eclipselink操作PostgreSQL数据库
首先确保您已经安装了PostgreSQL.您可以参考我这篇文章PostgreSQL扫盲教程. 使用Eclipse创建一个新的JPA project: Platform选择EclipseLink,作为J ...