Distinct Values

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4869    Accepted Submission(s): 1659

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
 
 
给出q个[l,r]   要求[l,r]范围内数字不重复 ,求字典序最小的满足q个要求的序列。
 
 
首先预处理出来覆盖每一个点的最左端点pre[i] ,用p从1开始 和  pre[i]比较,(因为当前区间是[pre[i], i],  上个区间是 [p, i-1] )  如果 p < pre[i] , 就把[p, pre[i]-1] 的数都释放了(插入set还能用)如果 p > pre[i], 直接取set.begin().
 
 
 
 
  1. // D
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define rep(i,a,n) for (int i=a;i<n;i++)
  5. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  6. #define pb push_back
  7. #define mp make_pair
  8. #define all(x) (x).begin(),(x).end()
  9. #define fi first
  10. #define se second
  11. #define SZ(x) ((int)(x).size())
  12. typedef vector<int> VI;
  13. typedef long long ll;
  14. typedef pair<int,int> PII;
  15. const ll mod=;
  16. ll powmod(ll a,ll b) {ll res=;a%=mod; assert(b>=); for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
  17. ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
  18. // head
  19.  
  20. const int N=;
  21. int _,n,m,pre[N],l,r,ret[N];//pre维护覆盖i的最左端点
  22. int main() {
  23. for (scanf("%d",&_);_;_--) {
  24. scanf("%d%d",&n,&m);
  25. rep(i,,n+) pre[i]=i;
  26. rep(i,,m) {
  27. scanf("%d%d",&l,&r);
  28. pre[r]=min(pre[r],l);
  29. per(i,,n) pre[i]=min(pre[i],pre[i+]);//pre[i]是pre[i]和pre[i+1]的最小值
  30. int pl=;//从1开始 和覆盖每个点的最左端点pre[i]比较
  31. set<int> val;
  32. rep(i,,n+) val.insert(i);//维护最小可用的数
  33. rep(i,,n+) {
  34. //上个 [pl, i-1]
  35.  
  36. //当前 [pre[i], i]
  37. while (pl<pre[i]) {//小于pre[i]的点的值 插入set
  38. val.insert(ret[pl]);
  39. pl++;
  40. }
  41. ret[i]=*val.begin();//不小于直接取最小的数放进去
  42. val.erase(ret[i]);//删除刚放入的数
  43. }
  44. rep(i,,n+) printf("%d%c",ret[i]," \n"[i==n]);
  45. }
  46. }
 

HDU6301 Distinct Values (多校第一场1004) (贪心)的更多相关文章

  1. HDU6581 Vacation (HDU2019多校第一场1004)

    HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...

  2. 2019年杭电多校第一场 1004题Vacation(HDU6581+数学)

    题目链接 传送门 题意 有\(n+1\)辆车要过红绿灯,告诉你车的长度.与红绿灯的起点(题目假设红绿灯始终为绿).车的最大速度,问你第\(0\)辆车(距离最远)车头到达红绿灯起点的时间是多少(每辆车最 ...

  3. hdu多校第一场1004(hdu6581)Vacation 签到

    题意:有n+1辆车,每辆车都有一定的长度,速度和距离终点的距离,第1-n辆车在前面依次排列,第0辆车在最后面.不允许超车,一旦后车追上前车,后车就减速,求第0辆车最快什么时候能到达终点? 思路:对于每 ...

  4. 2019HDU多校第一场 String 贪心

    题意:给你一个字符串,问是否存在一个长度为m的子序列,子序列中对应字符的数目必须在一个范围内,问是否存在这样的字符串?如果存在,输出字典序最小的那个. 思路:贪心,先构造一个序列自动机,序列自动机指向 ...

  5. 2019牛客多校第一场 I Points Division(动态规划+线段树)

    2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...

  6. 牛客多校第一场 B Inergratiion

    牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...

  7. 2019年牛客多校第一场B题Integration 数学

    2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...

  8. 2019HDU多校第一场1001 BLANK (DP)(HDU6578)

    2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...

  9. 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心

    Distinct Values Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. Celery-4.1 用户指南: Concurrency (并发)

    简介 Eventlet 的主页对它进行了描述:它是一个python的并发网络库,可以让你更改如何运行你的代码而不是怎么编写代码. 对高可扩展非阻塞IO操作,它使用 epoll或者libevent. C ...

  2. libstdc++.so.6

    libstdc++.so.6遇到的问题: 1.提示version `GLIBCXX_3.4.14' not found /usr/lib64/libstdc++.so.: version `GLIBC ...

  3. 使用setTimeout 来实现setInterval的效果

    直接上代码,实现的核心就是在延时的情况下递归的调用自己, x=0 y=-1 function countMin( ) { y=y+1 document.displayMin.displayBox.va ...

  4. 图解JVM和Tomcat类加载机制

    说到本篇的tomcat类加载机制,不得不说翻译学习tomcat的初衷. 之前实习的时候学习javaMelody的源码,但是它是一个Maven的项目,与我们自己的web项目整合后无法直接断点调试.后来同 ...

  5. VotingClassifier

    scores : array of float, shape=(len(list(cv)),) Array of scores of the estimator for each run of the ...

  6. mysql case

    1.table CREATE TABLE `lee`(`id` INT(10) NOT NULL auto_increment,`name` varchar(20) DEFAULT null,`bir ...

  7. 【WebRTC】简介

    WebRTC 名称源自网页实时通信(英语:Web Real-Time Communication)的缩写,是一个支持网页浏览器进行实时语音对话或视频对话的API.它于2011年6月1日开源并在Goog ...

  8. 并发之AtomicInteger

    并发之AtomicInteger 1 java.util.concurrent.atomic概要     在java.util.concurrent.atomic包下存在着18个类,其中Integer ...

  9. WebView三个方法区别(解决乱码问题)

    最近使用WebView加载中文网页的时候出现乱码问题,网上整理下基本解决方法: 其实我发现这不管是在线还是离线显示都可以使用LoadUrl方法!联网时好像是默认utf-8,离线读取本地时需要设置默认编 ...

  10. jquery.pagination.js使用

    直接上代码: <script type="text/javascript"> var pageIndex = 1; //页面索引初始值 var pageSize = 1 ...