问题 D: Distinct Values

时间限制: 1 Sec  内存限制: 128 MB
提交: 13  解决: 5
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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.

输入

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.

输出

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.

样例输入

3
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4

样例输出

1 2
1 2 1 2
1 2 3 1 1

思路:把一个区间的端点中值较大的一个放在前面,向后压倒!  详见代码:

AC代码:

#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
priority_queue<int,vector<int>,greater<int> > store;
int t,n,m,l,r,a[];
int main()
{
scanf("%d",&t);
while(t--)
{
ans.clear();
while(!store.empty()) store.pop();
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++)
{
a[i]=i;
store.push(i);
}
while(m--)
{
scanf("%d %d",&l,&r);
a[l]=max(a[l],r);
}
int cnt=,now=;
for(int i=;i<=n;i++)
{
if(a[i]<now) continue;
while(now>a[cnt+] && cnt+<now)
{
store.push(ans[cnt]);
cnt++;
}
while(now<=a[i])
{
ans.push_back(store.top());
store.pop();
now++;
}
}
for(int i=;i<ans.size();i++)
{
if(i==) printf("%d",ans[i]);
else printf(" %d",ans[i]);
}
printf("\n");
}
return ;
}

Distinct Values(贪心)的更多相关文章

  1. 2018 Multi-University Training Contest 1 Distinct Values 【贪心 + set】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6301 Distinct Values Time Limit: 4000/2000 MS (Java/Ot ...

  2. hdu 6301 Distinct Values (贪心)

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

  3. HDU6301 Distinct Values (多校第一场1004) (贪心)

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

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

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

  5. hdu多校1004 Distinct Values

    Distinct Values Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): ...

  6. hdu 6301 Distinct Values (2018 Multi-University Training Contest 1 1004)

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

  7. HDU 多校对抗赛 D Distinct Values

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

  8. hdu 6301 Distinct Values (思维+set)

    hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...

  9. hdu 6301 Distinct Values(贪心)题解

    题意:长为n的串,给你m个区间,这些区间内元素不重复,问这样的串字典序最小为? 思路:用set保存当前能插入的元素,这样就能直接插入最小元素了.对操作按l排序,因为排过的不用排,所以两个指针L,R是一 ...

随机推荐

  1. 无法加载MainifestResourceTransformer

    Cannot load implementation hint 'org.apache.maven.plugins.shade.resource.MainifestResourceTransforme ...

  2. Git入门 时光穿梭鸡 版本回退 工作区 暂存区

    分布式集中式 CVS及SVN都是集中式的版本控制系统 , 而Git是分布式版本控制系统 集中式版本控制系统,版本库是集中存放在中央服务器的, 而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得 ...

  3. 51nod 1086【背包·DP】

    思路: 如果体积乘以数量>=W,那么直接用完全背包模型.如果不到的话,用二进制优化就好了. 基础题,感觉这样写很优雅?回去睡觉. #include <bits/stdc++.h> u ...

  4. 3d全景图

    http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Aggarwal_Panoramic_Stereo_Videos_CV ...

  5. Untiy ShaderLab 随手记录

    最基本形式 (先不考虑Fog) Shader "Nafio/TUnlit"{ Properties { _MainTex("TT",2D) = "wh ...

  6. php UTF8 转字节数组,后使用 MD5 计算摘要

    Hex.encodeHexString(md5.digest);按 UTF8 转字节数组,后使用 MD5 计算摘要,得到 16 字节数组,使用 Hex 转为长度为 32 的字符串,保持小写 bin2h ...

  7. centOS7.5上部署server jre1.8.0_192 tomcat-8.5.35 mysql-8.0.13

  8. xml布局文件

    https://blog.csdn.net/u013475386/article/details/44339035 gravity写在容器中中 layout_gravity写在控件中 layout_m ...

  9. DRF教程8-过滤

    在写后端api时,经常需要使用各种过滤条件,可以使用Q对查询集进行过滤,这里介绍一个新玩意儿 以下是基础文档 https://django-filter.readthedocs.io/en/maste ...

  10. java实现access数据上传

    一. --springMvc实现上传 https://blog.csdn.net/qian_ch/article/details/69258465 --转换成spring64位上传 https://b ...