题意是一个长度为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
 
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int pre[];
  8. int ret[];
  9.  
  10. int main()
  11. {
  12. ios::sync_with_stdio(false);
  13. int t;
  14. cin >> t;
  15.  
  16. while (t--)
  17. {
  18. set<int> s;
  19. int m, n;
  20. cin >> n >> m;
  21. for (int i = ; i <= n; i++)
  22. {
  23. pre[i] = i;
  24. s.insert(i);
  25. }
  26.  
  27. for (int i = ; i <= m; i++)
  28. {
  29. int l, r;
  30. cin >> l >> r;
  31. pre[r] = min(pre[r], l);
  32. }
  33.  
  34. for (int i = n - ; i > ; i--)
  35. pre[i] = min(pre[i], pre[i + ]);
  36.  
  37. int pos = ;
  38. for (int i = ; i <= n; i++)
  39. {
  40. while (pre[i] > pos)
  41. {
  42. s.insert(ret[pos]);
  43. pos++;
  44. }
  45. ret[i] = *s.begin();
  46. s.erase(ret[i]);
  47. }
  48.  
  49. for (int i = ; i <= n; i++)
  50. {
  51. cout << ret[i];
  52. if (i != n)
  53. cout << " ";
  54. }
  55. cout << endl;
  56. }
  57.  
  58. return ;
  59. }

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. Eclipse maven工程生命周期clean、compile、test、package

    1.清理. 编译 工程右键->Run As->Maven build... 清理.编译操作控制台信息输出: 2.测试  同清理.编译,goals改成test 3.打包  同清理.编译,go ...

  2. openstack resize 更新显卡驱动程序解决问题

  3. Halcon学习之六:获取Image图像中Region区域的特征参数

    area_center_gray ( Regions, Image : : : Area, Row, Column )    计算Image图像中Region区域的面积Area和重心(Row,Colu ...

  4. Mycat实战之连续分片

    1 按照日期(天)分片: 从开始日期算起,按照天数来分片 例如,从2017-11-01,每10天一个分片且可以指定结束日期 注意事项:需要提前将分片规划好,建好,否则有可能日期超出实际配置分片数 1. ...

  5. Hadoop IO 特性详解(1)

    本文结合hadoop : the definitive guide精心而作,包含作者的心血,希望可以帮助大家理解一点hdfs的皮毛,足矣.(charles@xingbod.cn) hadoop本身自带 ...

  6. java5 Condition用法--实现线程间的通信

    Condition的功能类似在传统线程技术中的Object.wait()和Object.natify()的功能,传统线程技术实现的互斥只能一个线程单独干,不能说这个线程干完了通知另一个线程来干,Con ...

  7. c语言语法目录一

    1.#include<stdio.h> include 是要告诉编译器,包含一个头文件 在c语言中,任何库函数调用都需要提前包含头文件 <头文件> 代表让c语言编译器去系统目录 ...

  8. PHP屏蔽关键字实现方法

    方法一: 思路 用正则去匹配关键字,把关键字用别的字符替换: 1 2 3 $str = "/你大爷|你麻痹|什么玩意|SB|你他妈/";  // 关键字正则字符串  $string ...

  9. 1-5 构建官方example-Windows平台

    https://github.com/facebook/react-native https://github.com/facebook/react-native.git  https://githu ...

  10. jsoup 的简单应用

    导入相关jar包 package jsoup.zr.com.utils; import java.io.IOException; import java.util.List; import org.j ...