题意是一个长度为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. krpano之背景音乐

    步骤: 1.添加音乐控制插件 <!-- START:音乐控制 --> <plugin name="soundinterface" url="%SWFPA ...

  2. python 模块 optparse

    optparse,是一个能够让程式设计人员轻松设计出简单明了.易于使用.符合标准的Unix命令列程式的Python模块.生成使用和帮助信息. 下面是一个简单的示例: import optparse p ...

  3. 【原】Coursera—Andrew Ng机器学习—编程作业 Programming Exercise 3—多分类逻辑回归和神经网络

    作业说明 Exercise 3,Week 4,使用Octave实现图片中手写数字 0-9 的识别,采用两种方式(1)多分类逻辑回归(2)多分类神经网络.对比结果. (1)多分类逻辑回归:实现 lrCo ...

  4. Nginx 下配置Laravel 错误404

    宝塔的访问路径改一下 在站点的配置文件下面server里面加上 location / { try_files $uri $uri/ /index.php?$query_string; } 然后重启Ng ...

  5. opencv3 图片模糊操作-均值滤波 高斯滤波 中值滤波 双边滤波

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  6. python 添加日期

    import pandas as pd applydata['apply_time'] = pd.to_datetime(applydata.apply_time)# applydata.apply_ ...

  7. 打印单据,A4纸,每个单据占一个A4纸,两个单据之间不挨着

    打印单据,A4纸,每个单据占一个A4纸,两个单据之间不挨着 <style type="text/css" media="print">.Noprin ...

  8. 安装sql server 2008重启失败

    sql server2008安装时提示重启计算机失败怎么办   安装SQL Server 2008时,经常会遇到这样一个问题,软件提示“重启计算机失败”,如果忽略的话,会给后面的安装带来很大的麻烦,这 ...

  9. vis用于做3D图表的js插件

    vis.js用于做3D图表:(浏览网站需要FQ)实例:http://visjs.org/graph3d_examples.html代码下载:https://github.com/almende/vis

  10. elasticsearch plugin

    bin/plugin -install de.spinscale/elasticsearch-plugin-suggest/0.90.5-0.9 plugin -install mobz/elasti ...