hiaki has an array of nn positive integers. You are told some facts about the array: for every two elements aiai and ajaj in the subarray al..ral..r (l≤i<j≤rl≤i<j≤r), ai≠ajai≠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 TT, indicating the number of test cases. For each test case: 

The first line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) -- the length of the array and the number of facts. Each of the next mm lines contains two integers lili and riri (1≤li≤ri≤n1≤li≤ri≤n). 

It is guaranteed that neither the sum of all nn nor the sum of all mm exceeds 106106.

Output

For each test case, output nn 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

题意:给你n组数,没每组有L,R两个数,数组a[n],L ~ R区间内的正整数各部相同,让你输出字典序最小的数组;

题解:先将这些组数据按L1<L2 ,R1>R2 的优先级排序,可以用set<int> 维护还可以用的数字有哪些,开始将1~n全部加入到set中,然后从1  erase去第一个node 的r-1个数字,然后,令ll 为node[1].l rr为node[1].r,对于后面的node分3中情况:

1.如果node[i].r <= r,说明这个区间已经更新过了,且满足字典序最小,数字不同

2.如果node[i].l>r,则为一个新的开始,将a[l]~a[r]的数字加入到set里面,就从set.begin()开始 将*set.begin()赋值给a[node[i].l]到a[node[i].r],每赋值一个,set就删除一个,更新l,r的值

3.如果node[i].l<=r,则和上面2类似,就是区间变为 r~node[i].r;

参考代码为:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int maxn=1e5+10;
int T,n,m,flag[maxn];
struct Node{
int l,r;
bool operator < (const Node&b) const
{
return l==b.l? r>b.r : l<b.l;
}
} node[maxn];
set<int> s1;
int main()
{
scanf("%d",&T);
while(T--)
{
s1.clear();
memset(flag,0,sizeof flag);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) s1.insert(i);
for(int i=1;i<=m;i++) scanf("%d%d",&node[i].l,&node[i].r);
sort(node+1,node+1+m);
for(int i=node[1].l,j=1;i<=node[1].r;i++,j++) s1.erase(j),flag[i]=j;
int l=node[1].l,r=node[1].r;
for(int i=2;i<=m;i++)
{
if(node[i].r<=r) continue;
if(node[i].l>r)
{
for(int k=l;k<=r;k++) s1.insert(flag[k]);
for(int k=node[i].l;k<=node[i].r;k++) flag[k]=*s1.begin(),s1.erase(flag[k]);
l=node[i].l,r=node[i].r;
}
else
{
for(int k=l;k<node[i].l;k++) s1.insert(flag[k]);
for(int k=r+1;k<=node[i].r;k++) flag[k]=*s1.begin(),s1.erase(flag[k]);
l=node[i].l,r=node[i].r;
}
}
for (int i=1;i<=n;++i) printf("%d%c",flag[i]==0? 1 : flag[i],i==n? '\n':' ');
}
return 0;
}

2018HDU多校训练一 D Distinct Values的更多相关文章

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

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

  2. 2018HDU多校训练-3-Problem G. Interstellar Travel

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6325                                   Interstellar Tra ...

  3. 2018HDU多校训练-3-Problem M. Walking Plan

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6331 Walking Plan  Problem Description There are n inte ...

  4. 2018HDU多校训练-3-Problem F. Grab The Tree

    Little Q and Little T are playing a game on a tree. There are n vertices on the tree, labeled by 1,2 ...

  5. 2018HDU多校训练-3-Problem D. Euler Function

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...

  6. 2018HDU多校训练一 K - Time Zone

    Chiaki often participates in international competitive programming contests. The time zone becomes a ...

  7. 2018HDU多校训练一 C -Triangle Partition

    Chiaki has 3n3n points p1,p2,-,p3np1,p2,-,p3n. It is guaranteed that no three points are collinear.  ...

  8. 2018HDU多校训练一 A - Maximum Multiple

    Given an integer nn, Chiaki would like to find three positive integers xx, yy and zzsuch that: n=x+y ...

  9. hdu多校1004 Distinct Values

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

随机推荐

  1. Ansible之常用模块(一)

    ansible之所以功能强大,不是ansible本身,是因为它有众多的模块,前文我们介绍了ansible的基础介绍,系列命令的用法以及选项的说明,通过前文的学习我们知道了ansible是基于pytho ...

  2. go 学习笔记之咬文嚼字带你弄清楚 defer 延迟函数

    温故知新不忘延迟基础 A "defer" statement invokes a function whose execution is deferred to the momen ...

  3. Graphviz 画图的一些总结

    Graphviz Graphviz 是一个自动排版的作图软件,可以生成 png pdf 等格式. 一切以官方文档为准,博客只是参考.这里做一个自己学习的记录. dot 语法介绍 部分图形属性介绍 示例 ...

  4. nyoj 266-字符串逆序输出 (isdigit(), geline(cin, my_string))

    266-字符串逆序输出 内存限制:64MB 时间限制:3000ms 特判: No 通过数:15 提交数:18 难度:0 题目描述: 给定一行字符,逆序输出此行(空格.数字不输出) 输入描述: 第一行是 ...

  5. Python基础教程(第3版)学习笔记

    第1章.基础 1.几个小知识点 多用 help() 帮助文档 除法运算 / 除法运算,得到结果为浮点数: // 整除运算,得到整数值(向下取整): % 取余操作 (结果符号与除数符号相同),本质上: ...

  6. Js获取宽高度的归纳总结

    首先,先吓唬一下我们的小白们!在js中的描述宽高的可以细分有22种. window.innerWidth //除去菜单栏的窗口宽度 window.innerHeight//除去菜单栏的窗口高度 win ...

  7. 4.vim编辑器

    把光标移动文件头 gg 把光标移动文件尾 G 移动到行首 ^ 移动到行尾 $ 移动到指定行 :n 回车

  8. 20190926-2 选题 Scrum立会报告+燃尽图05

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/8678 一.小组情况组长:迟俊文组员:宋晓丽 梁梦瑶 韩昊 刘信鹏队名:扛 ...

  9. 每天复现一个漏洞--vulhub

    phpmyadmin scripts/setup.php 反序列化漏洞(WooYun-2016-199433) 漏洞原理:http://www.polaris-lab.com/index.php/ar ...

  10. 【Luogu P2471】[SCOI2007]降雨量

    Luogu P2471 啊啊啊啊这真是一道史上最毒瘤的题目!!!!! 题意就是给出n个年份的降雨量 询问:"自从\(y\)年以来\(x\)年的降雨量最大"的正确性. 显然有多种情况 ...