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. Ansibile之playbook初识

    一.playbook简介 ansiblie的任务配置文件被称为playbook,俗称“剧本”,每一个剧本(playbook)中都包含了一系列的任务,这每个任务在ansible中又被称为“戏剧”(pla ...

  2. springboot封装JsonUtil,CookieUtil工具类

    springboot封装JsonUtil,CookieUtil工具类 yls 2019-9-23 JsonUtil public class JsonUtil { private static Obj ...

  3. css字体图标的制作

    我介绍的这个办法是直接在 "阿里巴巴图标库"中制作的,方便快捷 1. 首先到 "阿里巴巴图标库"中找到你想要的图片,然后选择加入购物车 接着我们点击右上角的购物 ...

  4. 怎样用JS给,option添加“选中”属性

    <html> <head> <script> window.onload = function(){ var opts = document.getElementB ...

  5. Linux运维利器之ClusterShell

    一.简介 实验室机房有大概百台的服务器需要管理,加上需要搭建Hadoop以及Spark集群等,因此,一个轻量级的集群管理软件就显得非常有必要了.经过一段时间的了解以及尝试,最终选择了clustersh ...

  6. python:调用bash

    利用os模块 python调用Shell脚本,有三种方法: os.system(cmd)返回值是脚本的退出状态码 os.popen(cmd)返回值是脚本执行过程中的输出内容 commands.gets ...

  7. 【Linux系列】Centos 7安装 Redis(六)

    目的 本文主要介绍以下两点: 一. 安装Redis 二. 设置开机启动项 演示 一. 安装Redis 打开Redis官网,右击复制链接. yum install -y gcc # 先更新下编译环境 c ...

  8. linux计算机网络基础

    OSI7层协议和TCP/IP4层网络协议 第一层:物理层,定义各种物理设备的规范,如通信距离,接口大小等. 第二层:数据链路层,基于mac地址通信是,数据报文封装和相应方式. 第三层:网络层,基于IP ...

  9. firebug和HTML查看源代码的区别

    1.审查元素或者开发者工具或firebug看到的html是现在实时性的内容,经过js修改的: 2.而网页查看源代码看到的是最开始浏览器收到的HTTP响应,静态的html.

  10. Jenkins修改默认主目录及数据迁移

    前言 在使用Jenkins做持续集成的初期,未能预估项目量的大小.于是乎,配置都是使用的默认配置,而Jenkins的默认主目录放在了服务器的根目录下. 随着时间的推移,项目量的持续增加,在运维过程中就 ...