hdu多校1004 Distinct Values
Distinct Values
Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
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. Input
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 (≤n,m≤) -- the length of the array and the number of facts. Each of the next m lines contains two integers li and ri (≤li≤ri≤n). It is guaranteed that neither the sum of all n nor the sum of all m exceeds . Output
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. Sample Input Sample Output Source
Multi-University Training Contest Recommend
liuyiding | We have carefully selected several similar problems for you:
用优先队列。先对x排个序。
不重叠 就从1到n开始复制
重叠 把和上一段没有重叠部分加入到 优先队列当中。然后队列不为空时就从队列里出。不然就上一个的最大值++;
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<functional>
#include<algorithm>
using namespace std;
priority_queue <int,vector<int>,greater<int> > q;
struct node
{
int x;
int y;
} a[];
int ans[];
bool cmp(node a,node b)
{
return a.x<b.x;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
ans[i]=;
for(int i=; i<=m; i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a+,a++m,cmp);
int l=,r=;
while(!q.empty())
{
q.pop();
}
int maxx=;
for(int i=; i<=m; i++)
{
if(a[i].y<=r)
{
continue;
}
if(a[i].x>r)
{
for(int j=a[i].x,k=; j<=a[i].y; j++,k++)
{
ans[j]=k;
maxx=k;
}
while(!q.empty())
{
q.pop();
}
l=a[i].x;
r=a[i].y; }
else
{
for(int j=l;j<a[i].x;j++)
{
q.push(ans[j]);
}
for(int j=r+;j<=a[i].y;j++)
{
if(!q.empty())
{
ans[j]=q.top();
q.pop();
}
else
{
ans[j]=(++maxx);
}
}
l=a[i].x;
r=a[i].y;
}
}
for(int i=; i<n; i++)
cout<<ans[i]<<" ";
cout<<ans[n]<<endl; }
return ;
}
hdu多校1004 Distinct Values的更多相关文章
- HDU多校(Distinct Values)
Problem Description Chiaki has an array of n positive integers. You are told some facts about the ar ...
- 2018 杭电多校1 - Distinct Values
题目链接 Problem Description Chiaki has an array of n positive integers. You are told some facts about t ...
- 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 ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
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的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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 1 Distinct Values 【贪心 + set】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Ot ...
随机推荐
- css的postion属性
在实际项目中,发现postion这个属性经常使用而且常常很重要,所以总结整理一下知识点 css中postion属性有以下可选值,分别是:static,absolute, fixed, relative ...
- Python lambda 表达式
def ds(x): *x+ print(ds()) g = lambda x:*x+ print(g()) #------------ def sf(a,b): return a+b print(s ...
- Java问题解决:Java compiler level does not match the version of the installed Java project facet.
问题原因:Java编译器级别与Facted Project 中的Java 版本设定不匹配. 解决办法:将两者设置一致 1.查看Java compiler level : 选中项目右键propertie ...
- 为 10000+ 业务系统提供数据可视化能力的 AntV 又进化了
小蚂蚁说: 2018 年 AntV 品牌日以知新.知心为主题,旨在让产品一直「知新」,与用户一直「知心」.AntV 是蚂蚁金服全新一代数据可视化解决方案,致力于提供一套简单方便.专业可靠.无限可能的数 ...
- 【BZOJ】2331: [SCOI2011]地板
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2331 一眼插头DP... 考虑一个L形的东西,要构成它可以划分为两个阶段,即当前线段是拐了 ...
- MongoDB 对象操作
对象插入 >db.col.insert({title: 'MongoDB 教程', description: 'MongoDB 是一个 Nosql 数据库', by: 'xxx', url: ' ...
- [原][粒子特效][spark]调节器modifier
深入浅出spark粒子特效连接:https://www.cnblogs.com/lyggqm/p/9956344.html group添加modifier的方式: modifier An abstra ...
- Ubuntu16 源码方式安装postgresql数据库
依赖工具库 注意:默认用户名是postgres,以下命令是Ubuntu操作系统中的命令 make GCC Zlib 安装命令:sudo apt-get install zlib1g-dev注意有些软件 ...
- 学习笔记19—dpabi错误集
1.回归斜边量的时候千万不要用红色标记的地方,而要用紫色标记的地方
- java线程执行的优先级
1.1 线程的优先级 java 中的线程优先级的范围是1-10,默认的优先级是5.10极最高. 有时间片轮循机制.“高优先级线程”被分配CPU的概率高于“低优先级线程”.根据时间片轮循调度, ...