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. NW.js打包一个桌面应用

    1.安装nw(可以到官网:https://nwjs.io下载) npm install nw -g 2.创建一个最最简单的nw应用 在nwjs文件夹中 新建index.html和package.jso ...

  2. 从cocos2dx源代码看android和iOS跨平台那些事

    cocos2dx一个跨移动(平板)平台的游戏引擎,支持2d和3d,基于c/c++,网上介绍多在此不详叙.我们本篇关心的是跨平台那些事,自然而然就找到platform目录.好家伙,支持的操作平台还真不少 ...

  3. Linux安装telnet C/S 【白话文】

    1.安装telnet 和telnet-server yum -y install telnet yum -y install telnet-server 注意:在此安装过程中,会依赖解决xinetd的 ...

  4. aws msk

    1. 建立3个私网子网 2. 建立msk

  5. jdbc-mysql测试例子和源码详解

    目录 简介 什么是JDBC 几个重要的类 使用中的注意事项 使用例子 需求 工程环境 主要步骤 创建表 创建项目 引入依赖 编写jdbc.prperties 获得Connection对象 使用Conn ...

  6. H3C交换机、路由器 ssh登录配置

    VLAN 10  创建vlan并配好ip inter vlan 10 ip add  20.1.1.1  24 qu ip route-static 0.0.0.0 0 20.1.1.254  写好静 ...

  7. mysql通俗易懂的数据库连接池原理及模拟实现

    什么是数据库连接池? 当系统使用JDBC技术访问数据库时会创建一个connection对象,而该对象的创建过程是非常消耗资源的,并且创建对象的时间也特别长,假设系统一天有1万次的访问量,那么一天就会有 ...

  8. Precision,Recall,F1的计算

    Precision又叫查准率,Recall又叫查全率.这两个指标共同衡量才能评价模型输出结果. TP: 预测为1(Positive),实际也为1(Truth-预测对了) TN: 预测为0(Negati ...

  9. ctf比赛linux文件监控和恢复shell

    之前参加ctf比赛时候临时写的,有很多不足,不过可以用,就贴出来分享给大家,希望对大家有帮助. 脚本一:记录当前目录情况 #!/bin/bashfunction getdir(){    for el ...

  10. Python编译升级

    [root@localhost python]# tar xvf Python-3.6.9.tgz [root@localhost python]# cd Python-3.6.9/ [root@lo ...