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. HDU 5441 Travel(并查集+统计节点个数)

    http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给出一个图,每条边有一个距离,现在有多个询问,每个询问有一个距离值d,对于每一个询问,计算出有多少点 ...

  2. toggle 1.9 以后就被删除了

    toggle 1.9 以后就被删除了, 1.8.x  以前可用. $(function(){ $(".p_title").toggle( function(){ $(this).n ...

  3. 利用React Native 从0到1 开发一款兼容IOS和android的APP(仿造京东)

    最近有一部电视剧叫做<微微一笑很傻逼>里面有个男猪脚,人们都叫他大神~我觉得吧~大神是相对的~所以~啥事都得谦虚! 好了 今天介绍的是如何从0到1利用React Native开发一款兼容I ...

  4. 烽火HG220G-U E00L2.03M2000光猫改桥接教程

    烽火HG220G-U E00L2.03M2000光猫改桥接教程 P.S. 此教程同样适用于HG221G/HG260G-U/HG261G.(2016.12) 随着北京联通从原有的ONU升级到HGU之后, ...

  5. Oracel 中的分页

    --效率低 select * from (select rownum rn, d.* from table d )p where p.rn<=20 and p.rn>=10; select ...

  6. C.字符串(字符)操作

    1.memchr 检测的是一段内存,strchr 检测的是一个字符串 如果一段内存中有0x0的话,显然不能用strchr去查找的.建议看看两个函数的原型 strchr会停在 '\0',memchr不会 ...

  7. kotlin - 空安全

    空安全设计的操作符号 操作符 作用 ? 可空操作符,声明该值可为空 ?. 安全调用操作符       b?.length 如果b非空,就返回b.length,否则返回 null !! 非空断言运算符, ...

  8. 力扣(LeetCode) 852. 山脉数组的峰顶索引

    我们把符合下列属性的数组 A 称作山脉: A.length >= 3 存在 0 < i < A.length - 1 使得A[0] < A[1] < ... A[i-1] ...

  9. leecode第四题(寻找两个有序数组的中位数)

    题解: class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<i ...

  10. 03-python-装饰器

    装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象.它经常用于有切面需求的场景,比如:插入日志.性能测试.事务处理.缓存.权 ...