题意是一个长度为n的序列,给你m组区间(l,r),在这个区间里不能填入重复的数字,同时使整个序列字典序最小

同学用的优先队列,标程里使用的是贪心同时使用set维护答案序列

贪心是先采用pre数组来确定哪些区间不能重复,再通过记录从set弹出答案的位置来计算的

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
 
 #include <iostream>
#include <set>
#include <algorithm> using namespace std; int pre[];
int ret[]; int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t; while (t--)
{
set<int> s;
int m, n;
cin >> n >> m;
for (int i = ; i <= n; i++)
{
pre[i] = i;
s.insert(i);
} for (int i = ; i <= m; i++)
{
int l, r;
cin >> l >> r;
pre[r] = min(pre[r], l);
} for (int i = n - ; i > ; i--)
pre[i] = min(pre[i], pre[i + ]); int pos = ;
for (int i = ; i <= n; i++)
{
while (pre[i] > pos)
{
s.insert(ret[pos]);
pos++;
}
ret[i] = *s.begin();
s.erase(ret[i]);
} for (int i = ; i <= n; i++)
{
cout << ret[i];
if (i != n)
cout << " ";
}
cout << endl;
} return ;
}

HDU6301-2018ACM暑假多校联合训练1004-Distinct Values的更多相关文章

  1. HDU6333-2018ACM暑假多校联合训练1002-Harvest of Apples-莫队+费马小定理

    题意很简单啦,求S(n,m)的值 通过打表我们可以知道 S(n + 1, m) = S(n, m) * 2 - C(n, m); S(n - 1, m) = (S(n, m) + C(n - 1, m ...

  2. HDU6400-2018ACM暑假多校联合训练1004-Parentheses Matrix-构造

    Parentheses Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  3. HDU6336-2018ACM暑假多校联合训练4-1005-Problem E. Matrix from Arrays-前缀和

    题意是给了一种矩阵的生成方式 让你求两个左边之间的矩阵里面的数加起来的和(不是求矩阵的值) 没看标程之前硬撸写了160行 用了前缀和以后代码量缩短到原来的1/3 根据规律可以推导出这个矩阵是在不断重复 ...

  4. HDU6342-2018ACM暑假多校联合训练4-1011-Problem K. Expression in Memories

    Problem K. Expression in Memories Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262 ...

  5. HDU6330-2018ACM暑假多校联合训练Problem L. Visual Cube

    就是画个图啦 分三个平面去画orz #include <iostream> #include <cmath> #include <cstring> #include ...

  6. HDU6318-2018ACM暑假多校联合训练2-1010-Swaps and Inversions-树状数组

    本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大, ...

  7. HDU6299-2018ACM暑假多校联合训练1002-Balanced Sequence

    这个题的题意是给你n个字符串,认定()是一种平衡的串,两个以上连续的()()也是一种平衡的串,如果一对括号里面包含一个平衡的串,这个括号也被算在这个平衡的串之内, 如(()(()))是一个长度为8的平 ...

  8. HDU6298-2018ACM暑假多校联合训练1001-Maximum Multiple

    题意大致是给你一个整数n,让你确定是否有三个正整数x,y,z既能被n整除,又能x+y+z=n,并使xyz最大 从中根据规律可以看出,只有被3或被4整除的数才能满足题目要求 被3整除的最大值为n^3/3 ...

  9. HDU6308-2018ACM暑假多校联合训练1011-Time Zone

    题目大意就是给你UTC-8时区的时间 让你求对应时区的时间 哇 这个题 看似简单,但是一开始怎么都过不了啊 同学用自己写的read过了,后来看了一下各位大佬说改成分钟随便过,就随便过了 Problem ...

随机推荐

  1. Java和C#中的自定义元数据

    Java的annotation和C#的Attribute,可用来为语言增加语义,定义元数据. 转自:http://rednaxelafx.iteye.com/blog/464889 http://bl ...

  2. maven项目引入外部jar包的三种方式

    方式1:dependency 本地jar包 <dependency> <groupId>com.hope.cloud</groupId> <!--自定义--& ...

  3. Spring AOP面向切面编程详解

    前言 AOP即面向切面编程,是一种编程思想,OOP的延续.在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等等.在阅读本文前希望您已经对Spring有一定的了解 注:在能对代码进行添 ...

  4. centos 中没有 ifcfg-eth0 配置文件的解决办法

    用 CentOS-6.5-i386-LiveDVD.iso 镜像安装好CentOS 6.5系统后(已经把系统写入硬盘),发现ip在每次重启后都会还原,用ifconfig查看是有eth0网卡的(也有可能 ...

  5. 【原】Coursera—Andrew Ng机器学习—Week 1 习题—Linear Regression with One Variable 单变量线性回归

    Question 1 Consider the problem of predicting how well a student does in her second year of college/ ...

  6. 设置VMware Player中的虚拟机和宿主机共享文件

    设置VMware Player中的虚拟机和宿主机共享文件 试验环境: 虚拟机软件:VMware Player 6.0.3 宿主机os:windows7 虚拟机os:centos6.6(32位)   完 ...

  7. spring注解开发的准备工作

  8. js,javascript生成 UUID的四种方法

    全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) . GUID是一种由算法生成的二进制长度 ...

  9. 724. Find Pivot Index 找到中轴下标

    [抄题]: Given an array of integers nums, write a method that returns the "pivot" index of th ...

  10. EXE DLL等可执行程序添加版本号版权等信息

    在使用Microsoft Visual Studio开发工具等编写的exe或者dll等可执行文件时,我们往往需要对这些可执行文件添加版本号,公司,版权等信息. 1. 在我们需要添加各种信息的项目工程中 ...