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的更多相关文章

  1. HDU多校(Distinct Values)

    Problem Description Chiaki has an array of n positive integers. You are told some facts about the ar ...

  2. 2018 杭电多校1 - Distinct Values

    题目链接 Problem Description Chiaki has an array of n positive integers. You are told some facts about t ...

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

  4. HDU 多校对抗赛 D Distinct Values

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

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

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

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

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

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

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

  8. hdu 6301 Distinct Values (贪心)

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

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

随机推荐

  1. MySql查询功能梳理

    CREATE DATABASE CristinMysql Create table employee( eId int(9) not null auto_increment, eName varcha ...

  2. 【BZOJ】3576: [Hnoi2014]江南乐

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3576 很显然,这是一个multi-nim游戏. 注意:1.一个点的SG值就是一个不等于它的 ...

  3. C# 用面向对象的思想去编程

    再接上一篇博文,之前写的两篇博文虽然实现了功能,但是和控件之间的粘性太大,依赖于控件进行操作,所以这篇博文主要用面向对象的思想做一个Demo,将逻辑层与显示层剥离开 首先新建一个窗体文件,搭建界面完毕 ...

  4. VS2010.STL::list的一个bug

    1.ParameterAnswer_Parse(...) 下 FlistParameterOffset.clear(); 出错(list<DWORD>.clear()) (https:// ...

  5. libxml2的xpath检索中文

    ZC: xmlXPathEvalExpression(...) 当 xpath的字符串中 包含中文的时候,返回NULL,暂时不知道该怎么处理了... ZC: 下面是测试的一些代码/文件,留着以后再研究 ...

  6. MySQL 的 DISTINCT 应用于2列时

    SELECT DISTINCT vend_id告诉MySQL只返回不同(唯一)的 vend_id行,也就是在vend_id 有重复的行中,只保留一行,其他的不作输出.比如我创建了如下的student表 ...

  7. LRN(local response normalization--局部响应标准化)

    LRN全称为Local Response Normalization,即局部响应归一化层,LRN函数类似DROPOUT和数据增强作为relu激励之后防止数据过拟合而提出的一种处理方法.这个函数很少使用 ...

  8. docker下debian镜像开启ssh, 允许root用密码登录

    用的官方python镜像做开发, 暴露端口, 用pycharm ssh进去开发. 忽然发现本来ssh能连上, 但是更了新的python镜像连不上了. 有折腾了一下, 连上了. 主要是python官网镜 ...

  9. js怎么把一个数组里面的值作为一个属性添加到另一数组包含的对象里(小程序)

    上面这个需求我说的似乎不太明白,之前也是没有碰到过,也是最近在搞小程序,涉及到小程序前后台数据交互,展示的部分!!不太明白没关系等会我给大家举个例子,就明白了说起来有点拗口,一看就明白了,其实如果是原 ...

  10. Android 如何将手机屏幕投影到 PC 屏幕上或者投影仪上做演示?

    Android 如何将手机屏幕投影到 PC 屏幕上或者投影仪上做演示? 公司开发款APP,要给领导演示,总不能用手机面对面演示吧.所以找了好久,找到一款体验超好的: Total Control-帮助你 ...