Boring Class

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 900    Accepted Submission(s): 247

Problem Description

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
For each test case ,output the an integer m indicates the length of the longest subsequence as described.
Output m integers in the next line.
 
Sample Input
5
5 4 3 2 1
6 7 8 9 10
2
1 2
3 4
 
Sample Output
5
1 2 3 4 5
1
1
 
Author
ZSTU
 
Source

解题: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的更多相关文章

  1. 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 ...

  2. 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:  ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Mysql和网络连接相关的参数介绍

    摘要:同时还需要注意OS级别的网络监听队列的限制.因为如果OS的网络监听设置小于mysql的back_log设置的时候,我们加大back_log是没有意义的... max_conecctions:整个 ...

  2. 绘图-CAD-改快捷键

    CAD的快捷键应该在左手边,左手不离开键盘,右手不离开鼠标,这样的操作才有效率. arc 圆弧命令原命令是ARC Q 圆(CIRCLE) C 原快捷键C被定义为COPY,Q的形状类似圆,只是多了一个尾 ...

  3. Quartz.Net 使用心得(一)

    最近工作内容与定时任务相关,在实际使用Quartz过程中,有两个小问题较为困扰. 一.多个Trigger如何触发一个Job. 比如上下班打卡时推送消息,上班时间为9:30,打卡提醒时间为9:20较好. ...

  4. 鸟书shell 学习笔记(二) shell中正則表達式相关

    通配符与正則表達式的差别 通配符是bash原生支持的语法,正則表達式是处理字符串的一种表示方式, 正則表達式须要支持的工具支持才干够 语系设置 : export LANG=C grep alias 设 ...

  5. 图像算法研究---Adaboost算法具体解释

    本篇文章先介绍了提升放法和AdaBoost算法.已经了解的可以直接跳过.后面给出了AdaBoost算法的两个样例.附有详细计算过程. 1.提升方法(来源于统计学习方法) 提升方法是一种经常使用的统计学 ...

  6. linux驱动之poll操作

    POLL操作 1.POLL运行过程: poll是一个系统调用,其内核入口函数为sys_poll,sys_poll差点儿不做不论什么处理直接调用do_sys_poll,do_sys_poll的运行过程能 ...

  7. 广东工业大学2016校赛决赛-网络赛 1169 Problem A: Krito的讨伐 优先队列

    Problem A: Krito的讨伐 Description Krito终于干掉了99层的boss,来到了第100层.第100层可以表示成一颗树,这棵树有n个节点(编号从0到n-1),树上每一个节点 ...

  8. 剑指offer——01二维数组中的查找(Python3)

    题目:在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. ...

  9. Spark standalone运行模式(图文详解)

    不多说,直接上干货! 请移步 Spark standalone简介与运行wordcount(master.slave1和slave2) Spark standalone模式的安装(spark-1.6. ...

  10. 关于div中图片水平垂直居中的问题

    最近在做一个项目,里面涉及到不固定尺寸要在div里面水平垂直居中显示 我没有用table布局,而是用了div+css,找了很久,终于在网上找到解决方案,特此记录备用 关键核心代码如下: <div ...