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 ...
随机推荐
- KNN——图像分类
内容参考自:https://zhuanlan.zhihu.com/p/20894041?refer=intelligentunit 用像素点的rgb值来判断图片的分类准确率并不高,但是作为一个练习kn ...
- js 数组、对象转json 以及 json转 数组、对象
let jsonObj = $.parseJSON(jsonStr); //json字符串转化成json对象(jq方法) var jsonObj = JSON.parse(jsonStr); //js ...
- IIS7 配置Http重定向到Https
1.注意首先要安装url重定向模块 微软官方地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=7435 百度网盘地址:链接: ht ...
- 测试char,varchar存储
-- -- 表的结构 `user` -- DROP TABLE IF EXISTS `user`; CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) N ...
- java中如何认定一个变量和方法
对于变量,用变量名就可以认定.对于a ,你不能要求它既是int,又是double.这是错误的: 同理,对于方法,它的方法签名是:方法名+参数 通过签名,已经认定一个方法.你不能要求一个方法有多 ...
- N的阶乘(10000) 51 nod——1057 (大数)
像这些大整数加法或者乘法什么的思想都一样,就是截位存取,累积进位,最后逆序输出就可以啦 PS:小生是用10000来存取的,300MS就能A,如果单个存取有点危险,题目时间限制好像是1000ms,大家可 ...
- QT信号槽详解
1 QT信号槽详解 1.1 信号和槽的定义 信号是触发信号,例如按钮的点击触发一个clicked信号,槽是用来接收信号,并处理信号,相当于信号响应函数.一个信号可以关联多个槽函数,信 ...
- Centos 7 Docker安装配置
版本介绍 Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE.社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设 ...
- 牛客OI周赛4-提高组 B 最后的晚餐(dinner)
最后的晚餐(dinner) 思路: 容斥 求 ∑(-1)^i * C(n, i) * 2^i * (2n-i-1)! 这道题卡常数 #pragma GCC optimize(2) #pragma GC ...
- Codeforces 488B - Candy Boxes
B. Candy Boxes 题目链接:http://codeforces.com/problemset/problem/488/B time limit per test 1 second memo ...