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 ...
随机推荐
- HDU 1512 Monkey King(左偏树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1512 题意: 有n只猴子,每只猴子一开始有个力量值,并且互相不认识,现有每次有两只猴子要决斗,如果认识,就不打了 ...
- android获取屏幕宽度和高度
1. WindowManager wm = (WindowManager) getContext() .getSystemService(Context.WINDOW_SERVICE); int wi ...
- 【Selenium2】【Jenkins】
1. 下载Tomcat ,Windows7 环境,http://tomcat.apache.org/ 我下载的是版本8 2. 下载Jenkins,Windows7 环境,http://jenkins ...
- Oracle Single-Row Functions(单行函数)——NULL-Related Functions
参考资料:http://docs.oracle.com/database/122/SQLRF/Functions.htm#SQLRF006 Single-row functions return a ...
- idea使用教程(2)
目录: 1. open和import的区别 2.修改虚拟机配置信息 3.安装目录和设置目录 1. open和import的区别 open:如果本身就是idea项目,则可以直接open打开; impor ...
- STL_头文件
#include <string> #include <vector> #include <deque> #include <queue> #inclu ...
- vscode 常用扩展推荐
1.扩展推荐 Beautify Beautify code in place for VS Code CSS Formatter Formatter for CSS ESLint ...
- 学习笔记4-pathon的range()函数和list()函数
使用python的人都知道range()函数很方便,今天再用到他的时候发现了很多以前看到过但是忘记的细节.这里记录一下range(),复习下list的slide,最后分析一个好玩儿的冒泡程序. 这里记 ...
- 如何解决failed to load the jni shared library问题
如何解决failed to load the jni shared library问题 首先,我们来查看JDK是多少位的,在搜索框中输入cmd,然后打开命令行窗口. 在命令行中输入java -ve ...
- spring容器bean的作用域 & spring容器是否是单例的一些问题
Spring容器中Bean的作用域 当通过Spring容器创建一个Bean实例时,不仅可以完成Bean实例的实例化,还可以为Bean指定特定的作用域.Spring支持如下5种作用域: singleto ...