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

(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≤ri≤n

).

It is guaranteed that neither the sum of all n

nor the sum of all m

exceeds 106

.

 
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
3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
 
Sample Output
1 2
1 2 1 2
1 2 3 1 1
 
这回的航电多校有多个签到题 好评 
 
  这题就用L,R 两个指针维护这个ans序列
 

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

  1. hdu多校1004 Distinct Values

    Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...

  2. HDU 多校对抗赛 D Distinct Values

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

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

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

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

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

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

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

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

  7. hdu 6301 Distinct Values (贪心)

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

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

  9. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  10. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

随机推荐

  1. 【Set jsonObj = toJson( jsonString )】创建JSON实例

    创建JSON实例: 原型: toJson( jsonString ) 说明: 创建JSON实例 返回: [JSON] 参数: jsonString [可选] 可以用json格式字符串创建实例 示例: ...

  2. leetcode-最长上升子序列LIS

    转载原文地址:http://www.cnblogs.com/GodA/p/5180560.html 给定一个无序的整数数组,找到其中最长上升子序列的长度. 示例: 输入: [10,9,2,5,3,7, ...

  3. (原) MaterialEditor部- UmateriaEditor中 Node编译过程和使用(3)修正

    @author: 白袍小道 转载说明原处,爱护劳动 插件同步在GITHUB: DaoZhang_XDZ         说明 1.本篇是接着-----(原) MaterialEditor部- Umat ...

  4. OpenMPI源码剖析3:try_kill_peers 和 ompi_rte_abort 函数

    接着上一篇的疑问,我们说道,会执行 try_kill_peers 函数,它的函数定义在 ompi_mpi_abort.c 下: // 这里注释也说到了,主要是杀死在同一个communicator的进程 ...

  5. "Generative Adversarial Nets" Notes

    - Ian J.Goodfellow 中文翻译:https://blog.csdn.net/wspba/article/details/54577236 代码实现:https://github.com ...

  6. Fluent Python: Mutable Types as Parameter Defaults: Bad Idea

    在Fluent Python一书第八章有一个示例,未看书以先很难理解这个示例运行的结果,我们先看结果,然后再分析问题原因: 定义了如下Bus类: class Bus: def __init__(sel ...

  7. POJ 2104 K-th Number(划分树)

    Description You are working for Macrohard company in data structures department. After failing your ...

  8. Automatic Judge

    Description Welcome to HDU to take part in the second CCPC girls’ competition! A new automatic judge ...

  9. C++读取文件统计单词个数及频率

    1.Github链接 GitHub链接地址https://github.com/Zzwenm/PersonProject-C2 2.PSP表格 PSP2.1 Personal Software Pro ...

  10. Alpha冲刺——第二天

    Alpha第二天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...