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. kfka学习笔记一:使用Python操作Kafka

    1.准备工作 使用python操作kafka目前比较常用的库是kafka-python库,但是在安装这个库的时候需要依赖setuptools库和six库,下面就要分别来下载这几个库 https://p ...

  2. Codeforces Round #464 (Div. 2)

    A. Love Triangle time limit per test: 1 second memory limit per test: 256 megabytes input: standard ...

  3. 精简Linux文件路径

    精简Linux的文件路径: ..回退的功能 .留在当前文件夹 //仅仅保留一个/ abc/..要返回. 报错 删除最后一个/ 主要思路: 用栈记录路径的起始位置,讨论/后的不同情况就可以: #incl ...

  4. Django学习笔记(一)——安装,创建项目,配置

    疯狂的暑假学习之 Django学习笔记(一) 教材  书<The Django Book> 视频:csvt Django视频 1.创建项目 django‐admin.py startpro ...

  5. oracle rac下调节redo log file 文件大小

    rac下调节redo log file 文件大小 (1)查看当前日志信息: select * from v$logfile; (步骤2中得路径能够在这里MEMBER列看到,redo文件名称自己命名.比 ...

  6. webRequest

    chrome.webRequest 描述: 使用 chrome.webRequest API 监控与分析流量,还可以实时地拦截.阻止或修改请求.  可用版本: 从 Chrome 17 开始支持.  权 ...

  7. Linux环境thinkphp配置以及数据源驱动改动

    项目中须要用到thinkphp,以下简称tp. linux版本号:64位CentOS 6.4 Nginx版本号:nginx1.8.0 php版本号:php5.5.28 thinkphp版:3.2.3 ...

  8. dnscapy使用——本质上是建立ssh的代理(通过dns tunnel)

    git clone https://github.com/cr0hn/dnscapy.git easy_install Scapy 服务端: python dnscapy_server.py a.fr ...

  9. 什么是BOM头(字节顺序标记(ByteOrderMark))

    在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑ut ...

  10. 7个好用的在线YouTube视频下载工具

    title: 7个好用的在线YouTube视频下载工具 toc: false date: 2018-10-10 15:11:00 categories: methods tags: youtube C ...