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分治

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = ;
  4. struct Node {
  5. int l,r,id;
  6. bool operator<(const Node &t) const {
  7. if(r != t.r) return r < t.r;
  8. if(l != t.l) return l > t.l;
  9. return id < t.id;
  10. }
  11. } P[maxn],A[maxn],B[maxn];
  12. int n,tot,Li[maxn],C[maxn],dp[maxn];
  13. void update(int i,int val) {
  14. for(; i <= tot; i += i&(-i))
  15. C[i] = max(C[i],val);
  16. }
  17. void clr(int i) {
  18. for(; i <= tot; i += i&(-i)) C[i] = ;
  19. }
  20. int query(int i) {
  21. int ret = ;
  22. for(; i > ; i -= i&(-i)) ret = max(ret,C[i]);
  23. return ret;
  24. }
  25. void cdq(int L,int R) {
  26. if(L == R) {
  27. dp[P[L].id] = max(dp[P[L].id],);
  28. return;
  29. }
  30. int mid = (L + R)>>;
  31. cdq(mid+,R);
  32. int a = ,b = ;
  33. for(int i = L; i <= mid; ++i) A[a++] = P[i];
  34. for(int i = mid+; i <= R; ++i) B[b++] = P[i];
  35. sort(A,A+a);
  36. sort(B,B+b);
  37. int j = b-;
  38. for(int i = a-; i >= ; --i) {
  39. for(; j >= && B[j].r >= A[i].r; --j)
  40. update(B[j].l,dp[B[j].id]);
  41. dp[A[i].id] = max(dp[A[i].id],query(A[i].l) + );
  42. }
  43. for(int i = ; i < b; ++i) clr(B[i].l);
  44. cdq(L,mid);
  45. }
  46. int main() {
  47. while(~scanf("%d",&n)) {
  48. memset(dp,,sizeof dp);
  49. memset(C,,sizeof C);
  50. for(int i = tot = ; i < n; ++i) {
  51. scanf("%d",&P[i].l);
  52. P[i].id = i;
  53. Li[tot++] = P[i].l;
  54. }
  55. for(int i = ; i < n; ++i) {
  56. scanf("%d",&P[i].r);
  57. Li[tot++] = P[i].r;
  58. }
  59. sort(Li,Li + tot);
  60. tot = unique(Li, Li + tot) - Li;
  61. for(int i = ; i < n; ++i) {
  62. P[i].l = lower_bound(Li,Li+tot,P[i].l) - Li + ;
  63. P[i].r = lower_bound(Li,Li+tot,P[i].r) - Li + ;
  64. }
  65. cdq(,n-);
  66. int ret = ,pre = -;
  67. for(int i = ; i < n; ++i) ret = max(ret,dp[i]);
  68. printf("%d\n",ret);
  69. for(int i = ; i < n; ++i) {
  70. if(dp[i] == ret && (pre == - || P[i].l <= P[pre].l && P[i].r >= P[pre].r)) {
  71. if(pre != -) putchar(' ');
  72. printf("%d", + i);
  73. --ret;
  74. pre = i;
  75. }
  76. }
  77. puts("");
  78. }
  79. return ;
  80. }

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. jquery日历插件FullCalendar使用技巧

    原文链接:http://blog.csdn.net/u013493957/article/details/44920341   FullCalendar是一款基于jquery的日历控件,它有着很强大的 ...

  2. 《Python 源码剖析》之对象

    py一切皆对象的实现 Python中对象分为两类: 定长(int等), 非定长(list/dict等) 所有对象都有一些相同的东西, 源码中定义为PyObject和PyVarObject, 两个定义都 ...

  3. Cocos2d-x碰撞检測

    假设不适用Box2D物理引擎.那么要进行Cocos2d-x的碰撞检測那我们的方法往往就是进行"矩形和点"."矩形和矩形"这样粗略的碰撞检測.我们一般採取开启sc ...

  4. [Phonegap+Sencha Touch] 移动开发19 某些安卓手机上弹出消息框 点击后不消失的解决的方法

    Ext.Msg.alert等弹出框在某些安卓手机上,点击确定后不消失. 原因是: 消息框点击确定后有一段css3 transform动画,动画完毕后才会隐藏(display:none). 有些奇葩手机 ...

  5. Oracle新建Schema

    1.首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新用户的密码也可以不创建新 ...

  6. LightOJ--1094-- Farthest Nodes in a Tree(树的直径裸题)

    Farthest Nodes in a Tree Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu S ...

  7. 杂项-DB:DW/DWH(数据仓库)

    ylbtech-杂项-DB:DW/DWH(数据仓库) 数据仓库,英文名称为Data Warehouse,可简写为DW或DWH.数据仓库,是为企业所有级别的决策制定过程,提供所有类型数据支持的战略集合. ...

  8. JQuery学习系列篇(二)

    1.事件切换函数 hover([over],out); over鼠标移动到元素上要触发的函数,out鼠标移出元素要触发的函数. 2.togger 如果元素是可见的,切换为隐藏的:如果元素是隐藏的,切换 ...

  9. P1888 三角函数

    题目描述 输入一组勾股数a,b,c(a≠b≠c),用分数格式输出其较小锐角的正弦值.(要求约分.) 输入输出格式 输入格式: 一行,包含三个数,即勾股数a,b,c(无大小顺序). 输出格式: 一行,包 ...

  10. Oracle安装后命令行中运行sqlplus / as sysdba出现错误ora-01031:insufficient privileges

    Win10安装Oracle后命令行中运行sqlplus as sysdba出现错误ora-01031insufficient privileges的解决方法 情景描述 错误样例 错误分析 解决方法 情 ...