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. Django学习总结- ③

    对象属性与继承关系: 对象属性 1. 显示属性 - 开发者手动定义的,直接看的到的 2. 隐式属性 - 系统根据需求,自动创建的对象 - objects 它是model.Manager对象 - 当我们 ...

  2. Git版本库工作流程图想

    对照廖雪峰的教程,发现有很多难以理解的地方,画了一个图想方便以后参考 首先两个基本命令反应了版本库最本质的工作流程,后面的命令其实都基于此git add 把文件修改添加到暂存区git commit 在 ...

  3. 【第六章】MySQL日志文件管理

    1.日志文件管理概述: 配置文件:/etc/my.cnf 作用:MySQL日志文件是用来记录MySQL数据库客户端连接情况.SQL语句的执行情况以及错误信息告示. 分类:MySQL日志文件分为4种:错 ...

  4. Python3.5 Keras-Theano(含其他库)windows 安装环境

    https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...

  5. c# html 导出excel

    [CustomAuthorize]        public FileResult ExportCustomerManagerVisitExcel(string dateType, string r ...

  6. 6.azkban的监控

    azkaban自带的监控flow自带的邮件功能SLA总结写程序监控job情况监控azkaban的元数据库使用azkaban API监控总结 azkaban自带的监控 azkban目前仅仅支持邮件监控, ...

  7. 软件工程-东北师大站-第二次作业psp

    1.本周PSP 2.本周进度条 3.本周累计进度图 代码累计折线图 博文字数累计折线图 本周PSP饼状图

  8. Mininet实验 MAC地址学习

    实验目的 了解交换机的MAC地址学习过程. 了解交换机对已知单播.未知单播和广播帧的转发方式. 实验原理 MAC(media access control,介质访问控制)地址是识别LAN节点的标识.M ...

  9. js 拼接字符串时,本来想要’#1′ ,返回的却是’#01′

    今天在操作一个元素时,id值是拼接的. var index = $(this).attr(‘index’);    //0var id = ‘#’ + (index+1);    //#01$(id) ...

  10. Alpha 冲刺3

    队名:日不落战队 安琪(队长) 今天完成的任务 组织第三次站立式会议. 完成了个人信息前端界面. 明天的计划 草稿箱前端界面. 个人信息扩展界面框架. 还剩下的任务 回收站前端界面. 信息修改前端界面 ...