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 ...
随机推荐
- Window下部署MySql数据库
官网下载地址:https://dev.mysql.com/downloads/mysql/,MySQL Community(社区版) Server 5.7.21,下载完毕后,解压文件. (1)在mys ...
- Python入门(1)
一.Python的安装 进入Python官方网站:https://www.python.org/,按照下图操作,下载Python的安装器 下载完成,打开下载好的可执行文件,可以看到如下界面. 然后等待 ...
- Matlab提速方法
1. 向量化. 尽量少用for循环. 2. 循环竖着走比横着走快. 3. 内置函数也有优化的空间 不少内置函数都有大量的error check.直接用profiler找出真正干活的.不少内置函数在网上 ...
- MyBatis中文文档
http://mybatis.github.io/mybatis-3/zh/index.html
- 一:yarn 介绍
yarn的了出现主要是为了拆分jobtracker的两个核心功能:资源管理和任务监控,分别对应resouceManager(RM)和applicationManager(AM).yarn中的任 ...
- POJ 3675 Telescope(简单多边形和圆的面积交)
Description Updog is watching a plane object with a telescope. The field of vision in the telescope ...
- 简单DP
1.一只小蜜蜂 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. Input输入数据的第一行是一个整数N,表 ...
- 2017-2018-2 20172323 『Java程序设计』课程 结对编程练习_四则运算
结对编程的好丽友 - 20172323 王禹涵:中缀转后缀 - 20172314 方艺雯:后缀表达式的计算 - 20172305 谭鑫:中缀表达式的输出 需求分析 能随机生成由使用者确定的任意多道四则 ...
- android 出现Make sure the Cursor is initialized correctly before accessing data from it
Make sure the Cursor is initialized correctly before accessing data from it 详细错误是:java.lang.IllegalS ...
- Qt窗口及控件-QTreeview/QTableView排序问题
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt-QTreeview/QTableView排序问题 本文地址:http://tec ...