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. Window下部署MySql数据库

    官网下载地址:https://dev.mysql.com/downloads/mysql/,MySQL Community(社区版) Server 5.7.21,下载完毕后,解压文件. (1)在mys ...

  2. Python入门(1)

    一.Python的安装 进入Python官方网站:https://www.python.org/,按照下图操作,下载Python的安装器 下载完成,打开下载好的可执行文件,可以看到如下界面. 然后等待 ...

  3. Matlab提速方法

    1. 向量化. 尽量少用for循环. 2. 循环竖着走比横着走快. 3. 内置函数也有优化的空间 不少内置函数都有大量的error check.直接用profiler找出真正干活的.不少内置函数在网上 ...

  4. MyBatis中文文档

    http://mybatis.github.io/mybatis-3/zh/index.html

  5. 一:yarn 介绍

        yarn的了出现主要是为了拆分jobtracker的两个核心功能:资源管理和任务监控,分别对应resouceManager(RM)和applicationManager(AM).yarn中的任 ...

  6. POJ 3675 Telescope(简单多边形和圆的面积交)

    Description Updog is watching a plane object with a telescope. The field of vision in the telescope ...

  7. 简单DP

      1.一只小蜜蜂   有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. Input输入数据的第一行是一个整数N,表 ...

  8. 2017-2018-2 20172323 『Java程序设计』课程 结对编程练习_四则运算

    结对编程的好丽友 - 20172323 王禹涵:中缀转后缀 - 20172314 方艺雯:后缀表达式的计算 - 20172305 谭鑫:中缀表达式的输出 需求分析 能随机生成由使用者确定的任意多道四则 ...

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

  10. Qt窗口及控件-QTreeview/QTableView排序问题

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt-QTreeview/QTableView排序问题     本文地址:http://tec ...