题目大意:给n个数,两种操作1:U  a b   更新第a个为b (从0开始)
2: Q    a ,b  查询 a,b之间LCIS(最长连续递增子序列)的长度。

Sample Input
1
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9
Sample Output

1
1
4
2
3
1
2
5

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <algorithm>
  4. #include <iostream>
  5. #define lson l,m,rt<<1
  6. #define rson m+1,r,rt<<1|1
  7. #define maxn 100005
  8. using namespace std;
  9.  
  10. int mlen[maxn<<],lmlen[maxn<<],rmlen[maxn<<];
  11. int num[maxn];
  12.  
  13. void pushup(int rt,int l,int r)
  14. {
  15. lmlen[rt]=lmlen[rt<<];
  16. rmlen[rt]=rmlen[rt<<|];
  17. mlen[rt]=max(mlen[rt<<],mlen[rt<<|]);
  18. int mid=(l+r)>>;
  19. int m=(r-l)+;
  20. if(num[mid]<num[mid+]) //左区间的右值小于右区间的左值可以合并
  21. {
  22. if(lmlen[rt]==m-(m>>)) lmlen[rt]+=lmlen[rt<<|];
  23. if(rmlen[rt]==(m>>)) rmlen[rt]+=rmlen[rt<<];
  24. mlen[rt]=max(mlen[rt],lmlen[rt<<|]+rmlen[rt<<]);
  25. }
  26. }
  27. void build(int l,int r,int rt)
  28. {
  29. if(l==r)
  30. {
  31. mlen[rt]=lmlen[rt]=rmlen[rt]=;
  32. return ;
  33. }
  34. int m=(l+r)>>;
  35. build(lson);
  36. build(rson);
  37. pushup(rt,l,r);
  38. }
  39. void update(int a,int l,int r,int rt)
  40. {
  41. if(l==r)
  42. {
  43. return;
  44. }
  45. int m=(l+r)>>;
  46. if(a<=m) update(a,lson);
  47. else update(a,rson);
  48. pushup(rt,l,r);
  49. }
  50.  
  51. int query(int L,int R,int l,int r,int rt)
  52. {
  53. //printf("%d %d %d %d %d\n",L,R,l,r,rt);
  54. if(L<=l&&r<=R)
  55. {
  56. return mlen[rt];
  57. }
  58. int m=(l+r)>>;
  59. if(R<=m) return query(L,R,lson); //与一般不同,不能是子集,只能全部属于才能直接查询子区间 返回子区间的mlen
  60. if(L>m) return query(L,R,rson); //否则是确认儿子区间是否能合并,并在三者之间取最大值
  61.  
  62. int ta,tb;
  63. ta=query(L,R,lson);
  64. tb=query(L,R,rson);
  65. int ans;
  66. ans=max(ta,tb);
  67. if(num[m]<num[m+]) //同上
  68. {
  69. int temp;
  70. temp=min(rmlen[rt<<],m-L+)+min(lmlen[rt<<|],R-m);
  71. ans=max(temp,ans);
  72. }
  73. return ans;
  74. }
  75.  
  76. int main()
  77. {
  78. int T,n,m;
  79. int i,j;
  80. char f[];
  81. int a,b;
  82. #ifndef ONLINE_JUDGE
  83. freopen("1.in","r",stdin);
  84. #endif
  85. scanf("%d",&T);
  86. for(i=;i<T;i++)
  87. {
  88. scanf("%d %d",&n,&m);
  89. for(j=;j<=n;j++)
  90. scanf("%d",&num[j]);
  91. build(,n,);
  92. while(m--)
  93. {
  94. scanf("%s",&f);
  95. if(f[]=='U')
  96. {
  97. scanf("%d %d",&a,&b);
  98. a++;
  99. num[a]=b;
  100. update(a,,n,);
  101. }
  102. else
  103. {
  104. scanf("%d %d",&a,&b);
  105. a++,b++;
  106. printf("%d\n",query(a,b,,n,));
  107. }
  108. }
  109. }
  110. return ;
  111. }

hdu 3308 线段树的更多相关文章

  1. hdu 3308(线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. HDU 3308 线段树单点更新+区间查找最长连续子序列

    LCIS                                                              Time Limit: 6000/2000 MS (Java/Oth ...

  3. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  4. hdu 3308 线段树 区间合并+单点更新+区间查询

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. HDU 3308 线段树求区间最长连续上升子序列长度

    题意:两种操作,Q L R查询L - R 的最长连续上升子序列长度,U pos val 单点修改值 #include <bits/stdc++.h> #define N 100005 us ...

  6. hdu 3308 线段树,单点更新 求最长连续上升序列长度

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. hdu 5877 线段树(2016 ACM/ICPC Asia Regional Dalian Online)

    Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  8. hdu 3974 线段树 将树弄到区间上

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. hdu 3436 线段树 一顿操作

    Queue-jumpers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

随机推荐

  1. python模块-platform

    #author:Blood_Zero #coding:utf- import platform print dir(platform) #获取platform函数功能 platform.archite ...

  2. 【Eclipse】eclipse生成类图、类交互图、包依赖图

    今天,在修改毕设论文的时候需要画类图,系统已经开发完成,如果手动拿PowerDesigner画类图太浪费时间,于是通过网上查阅资料发现eclipse可以集成一个插件生成类图,也可以生成包图.现在做记录 ...

  3. C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉

    为了提高httpwebrequest的执行效率,查到了一些如下设置 request.ServicePoint.Expect100Continue = false; request.ServicePoi ...

  4. linux用户权限 -> 系统特殊权限

    set_uid 运行一个命令的时候,相当于这个命令的所有者,而不是执行者的身份. suid的授权方法 suid 权限字符s(S),用户位置上的x位上设置. 授权方法: passwd chmod u+s ...

  5. Flask:操作SQLite3(0.1)

    Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2 本文介绍了第一次在Flask框架中操作SQLite3数据库的测试,参考了官网的文档Using SQLite 3 wit ...

  6. sld一张图

  7. Oracle 函数 “申请通过后,将该表中循环遍历到的所有内容插到另一个表中”

    create or replace function mcode_apply_insert_material(p_mca_no VARCHAR2, p_action VARCHAR2, p_wf_no ...

  8. pom.xml一个简单配置

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. MySQL学习笔记:coalesce

    函数:coalesce 作用:返回传入的参数中第一个非NULL的值 ); # ); # 如果传入的参数所有都是NULL,则返回NULL,比如: SELECT COALESCE(NULL, NULL, ...

  10. vuejs学习--递归组件(树型表格分享)

    前言 学习vue有一段时间了,最近使用vue做了一套后台管理系统,其中使用最多就是递归组件,也因为自己对官方文档的不熟悉使得自己踩了不少坑,今天写出来和大家一起分享. 递归组件 组件在它的模板内可以递 ...