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. Python 基础之socket编程(一)

    Python 基础之socket编程(一) 可以进行通信玩儿了,感觉不错不错,网络通信就像打电话,我说一句你听一句之后,你再说一句,我听一句,就这样.....下去了.不扯淡了,来来来,看看今天都搞了点 ...

  2. 新手小白的Linux学习之路

    大家好,我是一个零基础的新手小白,在此和大家分享一下新手小白的学习之路.欢迎各位大神指教!谢谢 Linux简介: Linux操作系统诞生于1991年10月,由芬兰赫尔辛基大学的在校生Linus Tor ...

  3. [LC]35题 Search Insert Position (搜索插入位置)

    ①英文题目 Given a sorted array and a target value, return the index if the target is found. If not, retu ...

  4. secureCRT安装与激活

    SecureCRT安装及激活方式 百度网盘地址: SecureCRT及激活软件的地址: 1. 安装secureCRT 百度网盘下载,点击scrt814-x64.exe,按照提示安装secureCRT, ...

  5. HTML建立超链接

      链接是HTML文档的最基本特征之一.超文本链接英文名为hyperlink,它能够让浏览器在各个独立的页面之间方便地跳转.超链接有外部链接.电子邮件链接.锚点链接等. a标签   网页中<a& ...

  6. ReentreantLock:重入锁

    ReentreantLock:重入锁 参考:https://www.cnblogs.com/nullzx/p/4968674.html 一). ReentrantLock与synchronized的区 ...

  7. 扛把子组20191107-4 beta week 2/2 Scrum立会报告+燃尽图 03

    此作业的要求参见https://edu.cnblogs.com/campus/nenu/2019fall/homework/9956 一.小组情况 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 韩 ...

  8. PL真有意思(五):数据类型

    前言 现在大多数程序设计语言中都有表达式和/或对象的类型概念.类型起着两种主要作用: 为许多操作提供了隐含的上下文信息,使程序员可以在许多情况下不必显示的描述这种上下文.比如int类型的两个对象相加就 ...

  9. Oracle数据库索引

    Oracle数据库索引 在关系数据库中,索引是一种与表有关的数据库结构,它可以使对应于表的SQL语句执行得更快.索引的作用相当于图书的目录,可以根据目录中的页码快速找到所需的内容. 对于数据库来说,索 ...

  10. 【论文阅读】A practical algorithm for distributed clustering and outlier detection

    文章提出了一种分布式聚类的算法,这是第一个有理论保障的考虑离群点的分布式聚类算法(文章里自己说的).与之前的算法对比有以下四个优点: 1.耗时短O(max{k,logn}*n), 2.传递信息规模小: ...