HDU多校(Distinct Values)
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
≠a
j
holds.
Chiaki would like to find a lexicographically minimal array which meets the facts.
, indicating the number of test cases. For each test case:
The first line contains two integers n
and m
(1≤n,m≤105
) -- the length of the array and the number of facts. Each of the next m
lines contains two integers li
and ri
(1≤li
≤r
i
≤n
).
It is guaranteed that neither the sum of all n
nor the sum of all m
exceeds 106
.
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.
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
1 2 1 2
1 2 3 1 1
while(L < qu[i].l) {
st.insert(ans[L]);
L++;
}
这些值可以重新插入
while(R < qu[i].r) {
if (R < qu[i].l-1) R++;
else {
R++;
ans[R] = *st.begin();
st.erase(st.begin());
}
}
这个其实类似于莫队的区间维护
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + ;
int t, n, m, ans[maxn];
struct node {
int l, r, flag;
} qu[maxn];
int cmp(node a, node b) {
if (a.l == b.l) return a.r < b.r;
return a.l < b.l;
}
int main() {
scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
for (int i = ; i < m ; i++) {
scanf("%d%d", &qu[i].l, &qu[i].r);
qu[i].flag = ;
}
sort(qu, qu + m, cmp);
set<int>st;
for (int i = ; i <= n ; i++) {
st.insert(i);
ans[i] = ;
}
for (int i = qu[].l ; i <= qu[].r ; i++) {
ans[i] = *st.begin();
st.erase(st.begin());
}
int L = qu[].l, R = qu[].r;
for (int i = ; i < m ; i++) {
while(L < qu[i].l) {
st.insert(ans[L]);
L++;
}
while(R < qu[i].r) {
if (R < qu[i].l-) R++;
else {
R++;
ans[R] = *st.begin();
st.erase(st.begin());
}
}
}
for (int i = ; i <= n ; i++) {
if (i != n) printf("%d ", ans[i]);
else printf("%d\n", ans[i]);
}
}
return ;
}
HDU多校(Distinct Values)的更多相关文章
- hdu多校1004 Distinct Values
Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...
- HDU 多校对抗赛 D Distinct Values
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的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- 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 ...
- HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 杭电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 ...
- 2018 HDU多校第四场赛后补题
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
- 2018 HDU多校第三场赛后补题
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
随机推荐
- 使用flask_limiter设定API配额
前言 闲来无事,突然想到了以前做过的关于后台API安全方面的事,关于接口访问配额的设置,flask有没有很好的库支持呢?一找还真有!主要是对照了库的官方文档自己写了下dome,以供参考. # -*- ...
- 树(Tree,UVA 548)
题目描述: 题目思路: 1.使用数组建树 //递归 2.理解后序遍历和中序遍历,建立左右子树 3.dfs深度搜索找出权重最小的路径 #include <iostream> #include ...
- kaldi - Online Audio Server(服务器客户端建立方法-旧版在线解码)
目录 一.服务器客户端识别系统建立方法 1. Command line to start the server(服务器端启动方式): 2. Command line to start the clie ...
- Struts2文件上传带进度条,虽然不是很完美
好久没有写东西,最近在做个项目,要用到文件h 传的,以前虽然也做上传,但是总觉得不好用 ,现在和队友合作做了一个带进度条的上传,觉得还行~~和大家分享一下. 首先说一下大概是这样实现的,在我们平时的上 ...
- codeforces 301D Yaroslav and Divisors(树状数组)
Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he ...
- NFC学习总结二
移动支付这事情热了总归还是会回归理性,就如同之前的10几年间的几次轮回一样.字面上看,移动支付比支付大也不大可能,有相同,有扩展,有交集有不通才是. NFC这事情也是说了快十年了,真心希望它能回归到其 ...
- (一)Model的产生及处理
MVC的概念其实最早可以追溯到很久很久以前,并不是WEB开发过程中所首创, 但是,MVC也适合WEB上的开发,并真正的在WEB开发领域广泛应用.MVC的第一个字母M是Model,承载着View层和Co ...
- Windows SDK 非模态对话框的消息处理
在SDK中使用非模态对话框时的几个问题: 1.为什么要调用IsDialogMessage?? 2.非模态对话框与主窗口有什么区别? 3.如果不调用IsDialogMessage,消息能不能传递到对话框 ...
- open-stf 安装篇(linux)
OpenSTF 百度MTC的远程真机调试 Testin的云真机 腾讯WeTest的云真机 阿里MQC的远程真机租用 什么是OpenSTF? OpenSTF是一个手机设备管理平台,可以对手机进行远 ...
- 载入其他同名源文件导致vs编译错误
今天下午工程编译的时候总是通不过,提示1,某个类没有某个成员,可是我去该类的头文件下查看,确实包括了这个成员啊.2,没有某个类,可是我明明定义了的. 检查了好久才发现 原来是,我打开了其他工程下的某一 ...