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 ...
随机推荐
- jquery日历插件FullCalendar使用技巧
原文链接:http://blog.csdn.net/u013493957/article/details/44920341 FullCalendar是一款基于jquery的日历控件,它有着很强大的 ...
- 《Python 源码剖析》之对象
py一切皆对象的实现 Python中对象分为两类: 定长(int等), 非定长(list/dict等) 所有对象都有一些相同的东西, 源码中定义为PyObject和PyVarObject, 两个定义都 ...
- Cocos2d-x碰撞检測
假设不适用Box2D物理引擎.那么要进行Cocos2d-x的碰撞检測那我们的方法往往就是进行"矩形和点"."矩形和矩形"这样粗略的碰撞检測.我们一般採取开启sc ...
- [Phonegap+Sencha Touch] 移动开发19 某些安卓手机上弹出消息框 点击后不消失的解决的方法
Ext.Msg.alert等弹出框在某些安卓手机上,点击确定后不消失. 原因是: 消息框点击确定后有一段css3 transform动画,动画完毕后才会隐藏(display:none). 有些奇葩手机 ...
- Oracle新建Schema
1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新用户的密码也可以不创建新 ...
- LightOJ--1094-- Farthest Nodes in a Tree(树的直径裸题)
Farthest Nodes in a Tree Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu S ...
- 杂项-DB:DW/DWH(数据仓库)
ylbtech-杂项-DB:DW/DWH(数据仓库) 数据仓库,英文名称为Data Warehouse,可简写为DW或DWH.数据仓库,是为企业所有级别的决策制定过程,提供所有类型数据支持的战略集合. ...
- JQuery学习系列篇(二)
1.事件切换函数 hover([over],out); over鼠标移动到元素上要触发的函数,out鼠标移出元素要触发的函数. 2.togger 如果元素是可见的,切换为隐藏的:如果元素是隐藏的,切换 ...
- P1888 三角函数
题目描述 输入一组勾股数a,b,c(a≠b≠c),用分数格式输出其较小锐角的正弦值.(要求约分.) 输入输出格式 输入格式: 一行,包含三个数,即勾股数a,b,c(无大小顺序). 输出格式: 一行,包 ...
- Oracle安装后命令行中运行sqlplus / as sysdba出现错误ora-01031:insufficient privileges
Win10安装Oracle后命令行中运行sqlplus as sysdba出现错误ora-01031insufficient privileges的解决方法 情景描述 错误样例 错误分析 解决方法 情 ...