HDU6301 Distinct Values (多校第一场1004) (贪心)
Distinct Values
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4869 Accepted Submission(s): 1659
Chiaki would like to find a lexicographically minimal array which meets the facts.
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.
2 1
1 2
4 2
1 2
3 4
5 2
1 3
2 4
1 2 1 2
1 2 3 1 1
// D
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=;
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;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head const int N=;
int _,n,m,pre[N],l,r,ret[N];//pre维护覆盖i的最左端点
int main() {
for (scanf("%d",&_);_;_--) {
scanf("%d%d",&n,&m);
rep(i,,n+) pre[i]=i;
rep(i,,m) {
scanf("%d%d",&l,&r);
pre[r]=min(pre[r],l);
per(i,,n) pre[i]=min(pre[i],pre[i+]);//pre[i]是pre[i]和pre[i+1]的最小值
int pl=;//从1开始 和覆盖每个点的最左端点pre[i]比较
set<int> val;
rep(i,,n+) val.insert(i);//维护最小可用的数
rep(i,,n+) {
//上个 [pl, i-1] //当前 [pre[i], i]
while (pl<pre[i]) {//小于pre[i]的点的值 插入set
val.insert(ret[pl]);
pl++;
}
ret[i]=*val.begin();//不小于直接取最小的数放进去
val.erase(ret[i]);//删除刚放入的数
}
rep(i,,n+) printf("%d%c",ret[i]," \n"[i==n]);
}
}
HDU6301 Distinct Values (多校第一场1004) (贪心)的更多相关文章
- HDU6581 Vacation (HDU2019多校第一场1004)
HDU6581 Vacation (HDU2019多校第一场1004) 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6581 题意: 给你n+1辆汽车, ...
- 2019年杭电多校第一场 1004题Vacation(HDU6581+数学)
题目链接 传送门 题意 有\(n+1\)辆车要过红绿灯,告诉你车的长度.与红绿灯的起点(题目假设红绿灯始终为绿).车的最大速度,问你第\(0\)辆车(距离最远)车头到达红绿灯起点的时间是多少(每辆车最 ...
- hdu多校第一场1004(hdu6581)Vacation 签到
题意:有n+1辆车,每辆车都有一定的长度,速度和距离终点的距离,第1-n辆车在前面依次排列,第0辆车在最后面.不允许超车,一旦后车追上前车,后车就减速,求第0辆车最快什么时候能到达终点? 思路:对于每 ...
- 2019HDU多校第一场 String 贪心
题意:给你一个字符串,问是否存在一个长度为m的子序列,子序列中对应字符的数目必须在一个范围内,问是否存在这样的字符串?如果存在,输出字典序最小的那个. 思路:贪心,先构造一个序列自动机,序列自动机指向 ...
- 2019牛客多校第一场 I Points Division(动态规划+线段树)
2019牛客多校第一场 I Points Division(动态规划+线段树) 传送门:https://ac.nowcoder.com/acm/contest/881/I 题意: 给你n个点,每个点有 ...
- 牛客多校第一场 B Inergratiion
牛客多校第一场 B Inergratiion 传送门:https://ac.nowcoder.com/acm/contest/881/B 题意: 给你一个 [求值为多少 题解: 根据线代的知识 我们可 ...
- 2019年牛客多校第一场B题Integration 数学
2019年牛客多校第一场B题 Integration 题意 给出一个公式,求值 思路 明显的化简公式题,公式是分母连乘形式,这个时候要想到拆分,那如何拆分母呢,自然是裂项,此时有很多项裂项,我们不妨从 ...
- 2019HDU多校第一场1001 BLANK (DP)(HDU6578)
2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...
- 杭电2018暑假多校第一场 D Distinct Values hdu6301 贪心
Distinct Values Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- Firefox切换页面默认显示语言
重新安装了下Firefox,发现页面语言变为中文,而我的有些脚本是在英文界面录的,因此想把默认语言改为英文. 方法如下: 工具 - 选项 - 语言(选择...),将英文上移到顶部 在做上面的修改之前, ...
- JVM中存储类信息的三个表格
摘自:<Java Performance>第三章 Internal Class Loading Data The HotSpot VM maintains three hash table ...
- C++的继承与接口
1.继承方式 三种继承方式,public,private,protected.注意,继承方式是相对于某一层类的方法而言,并不是相对于子类的对象而言.对于外部世界()对象来说,protected和pri ...
- dos 下bat 常用符号
1.@一般在它之后紧跟一条命令或一条语句,则此命令或语句本身在执行的时候不会显示在屏幕上.请把下面的代码保存为test.cmd文件,然后运行,比较一下两条echo语句在屏幕上的输出差异: ech ...
- Codeforces 1107E (Vasya and Binary String) (记忆化,DP + DP)
题意:给你一个长度为n的01串,和一个数组a,你可以每次选择消除一段数字相同的01串,假设消除的长度为len,那么收益为a[len],问最大的收益是多少? 思路:前两天刚做了POJ 1390,和此题很 ...
- phper 需要学习js
- Angular07 利用angular打造管理系统页面
1 创建一个新的angular应用 ng new adminSystem 2 利用WebStorm打开adminSystem应用 3 借助AdminLTE这个开源项目来辅助开发 AdminLTE项目: ...
- 生产者与消费者-1:N-基于list
一个生产者/多个消费者: /** * 生产者 */ public class P { private MyStack stack; public P(MyStack stack) { this.sta ...
- 已看1.熟练的使用Java语言进行面向对象程序设计,有良好的编程习惯,熟悉常用的Java API,包括集合框架、多线程(并发编程)、I/O(NIO)、Socket、JDBC、XML、反射等。[泛型]\
1.熟练的使用Java语言进行面向对象程序设计,有良好的编程习惯,熟悉常用的Java API,包括集合框架.多线程(并发编程).I/O(NIO).Socket.JDBC.XML.反射等.[泛型]\1* ...
- C语言-郝斌笔记-003数据类型
基本类型数据 整数 整型 —— int --4字节 短整型 —— short int ——2字节 长整型 —— long int ——8字节 浮点数[实 ...