2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 900 Accepted Submission(s): 247
Mr. Zstu and Mr. Hdu are taking a boring class , Mr. Zstu comes up with a problem to kill time, Mr. Hdu thinks it’s too easy, he solved it very quickly, what about you guys?
Here is the problem:
Give you two sequences L1,L2,...,Ln and R1,R2,...,Rn.
Your task is to find a longest subsequence v1,v2,...vm satisfies
v1≥1,vm≤n,vi<vi+1 .(for i from 1 to m - 1)
Lvi≥Lvi+1,Rvi≤Rvi+1(for i from 1 to m - 1)
If there are many longest subsequence satisfy the condition, output the sequence which has the smallest lexicographic order.
Input
There are several test cases, each test case begins with an integer n.
1≤n≤50000
Both of the following two lines contain n integers describe the two sequences.
1≤Li,Ri≤109
Output m integers in the next line.
解题:CDQ分治
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct Node {
int l,r,id;
bool operator<(const Node &t) const {
if(r != t.r) return r < t.r;
if(l != t.l) return l > t.l;
return id < t.id;
}
} P[maxn],A[maxn],B[maxn];
int n,tot,Li[maxn],C[maxn],dp[maxn];
void update(int i,int val) {
for(; i <= tot; i += i&(-i))
C[i] = max(C[i],val);
}
void clr(int i) {
for(; i <= tot; i += i&(-i)) C[i] = ;
}
int query(int i) {
int ret = ;
for(; i > ; i -= i&(-i)) ret = max(ret,C[i]);
return ret;
}
void cdq(int L,int R) {
if(L == R) {
dp[P[L].id] = max(dp[P[L].id],);
return;
}
int mid = (L + R)>>;
cdq(mid+,R);
int a = ,b = ;
for(int i = L; i <= mid; ++i) A[a++] = P[i];
for(int i = mid+; i <= R; ++i) B[b++] = P[i];
sort(A,A+a);
sort(B,B+b);
int j = b-;
for(int i = a-; i >= ; --i) {
for(; j >= && B[j].r >= A[i].r; --j)
update(B[j].l,dp[B[j].id]);
dp[A[i].id] = max(dp[A[i].id],query(A[i].l) + );
}
for(int i = ; i < b; ++i) clr(B[i].l);
cdq(L,mid);
}
int main() {
while(~scanf("%d",&n)) {
memset(dp,,sizeof dp);
memset(C,,sizeof C);
for(int i = tot = ; i < n; ++i) {
scanf("%d",&P[i].l);
P[i].id = i;
Li[tot++] = P[i].l;
}
for(int i = ; i < n; ++i) {
scanf("%d",&P[i].r);
Li[tot++] = P[i].r;
}
sort(Li,Li + tot);
tot = unique(Li, Li + tot) - Li;
for(int i = ; i < n; ++i) {
P[i].l = lower_bound(Li,Li+tot,P[i].l) - Li + ;
P[i].r = lower_bound(Li,Li+tot,P[i].r) - Li + ;
}
cdq(,n-);
int ret = ,pre = -;
for(int i = ; i < n; ++i) ret = max(ret,dp[i]);
printf("%d\n",ret);
for(int i = ; i < n; ++i) {
if(dp[i] == ret && (pre == - || P[i].l <= P[pre].l && P[i].r >= P[pre].r)) {
if(pre != -) putchar(' ');
printf("%d", + i);
--ret;
pre = i;
}
}
puts("");
}
return ;
}
2015 Multi-University Training Contest 3 hdu 5324 Boring Class的更多相关文章
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 Multi-University Training Contest 7 hdu 5378 Leader in Tree Land
Leader in Tree Land Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- struts配置问题
- 可序列化serializable的作用是什么
什么情况下需要序列化:a)当你想把的内存中的对象写入到硬盘的时候:b)当你想用套接字在网络上传送对象的时候: 为什么要序列化: 为了将对象可以以流的方式传输到其他位置,就必须要将该对象定义为可序列化的 ...
- [Spring实战系列](17)编写切点与声明切面
切点用于准确定位应该在什么地方应用切面的通知. 切点和通知是切面的最基本元素. 在Spring AOP中,须要使用AspectJ的切点表达式语言来定义切点. 关于Spring AOP的AspectJ切 ...
- 一步一步跟我学习hadoop(5)----hadoop Map/Reduce教程(2)
Map/Reduce用户界面 本节为用户採用框架要面对的各个环节提供了具体的描写叙述,旨在与帮助用户对实现.配置和调优进行具体的设置.然而,开发时候还是要相应着API进行相关操作. 首先我们须要了解M ...
- wikioi 1396 伸展树(两个模板)
题目描写叙述 Description Tiger近期被公司升任为营业部经理.他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来 ...
- GCD的小结
同步和异步的区别 同步:在当前线程中执行 异步:在另一条线程中执行 有4个术语比较容易混淆:同步.异步.并发.串行 同步和异步决定了要不要开启新的线程 同步:在当前线程中执行任务,不具备开启新线程的能 ...
- HttpClient简单操作
HttpClient 这个框架主要用来请求第三方服务器,然后获取到网页,得到我们需要的数据: HttpClient设置请求头消息User-Agent模拟浏览器 比如我们请求 www.tuicool.c ...
- Ubuntu 16.04或14.04里下安装搜狗输入法(图文详解)(全网最简单)
不多说,直接上干货! 其实啊,很简单 分三步走 1.添加fcitx的键盘输入法系统,因为sogou是基于fcitx的,而系统默认的是iBus: 2.安装sogou输入法: 3.设置系统参数及一些注意点 ...
- 案例分析:大数据平台技术方案及案例(ppt)
大数据平台是为了计算,现今社会所产生的越来越大的数据量,以存储.运算.展现作为目的的平台.大数据技术是指从各种各样类型的数据中,快速获得有价值信息的能力.适用于大数据的技术,包括大规模并行处理(MPP ...
- tp5数据库操作 Db类
一.链接数据库 1.配置文件定义 application\database.php 注意:数据表前缀更改,在文件的prefix选项 2.类定义 二.数据库的基本使用 namespace app\de ...