这个是动态的,所以要用线段树维护。代码里有注释因为ls敲成lsum,rs敲成rsum查错查了好久。。

  1. #include <set>
  2. #include <map>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <queue>
  6. #include <stack>
  7. #include <cctype>
  8. #include <cstdio>
  9. #include <string>
  10. #include <vector>
  11. #include <cstdlib>
  12. #include <cstring>
  13. #include <iostream>
  14. #include <algorithm>
  15. using namespace std;
  16. typedef unsigned long long ull;
  17. typedef long long ll;
  18. const int inf = 0x3f3f3f3f;
  19. const double eps = 1e-;
  20. template <class T>
  21. inline bool scan_d(T &ret)
  22. {
  23. char c;
  24. int sgn;
  25. if(c=getchar(),c==EOF) return ;
  26. while(c!='-'&&(c<''||c>''))
  27. c=getchar();
  28. sgn=(c=='-')?-:;
  29. ret=(c=='-')?:(c-'');
  30. while(c=getchar(),c>=''&&c<='')
  31. ret=ret*+(c-'');
  32. ret*=sgn;
  33. return ;
  34. }
  35.  
  36. const int maxn = 1e5+;
  37. int ls[maxn<<],rs[maxn<<]; //ls为区间左值,rs为区间右值 比较时要用到。
  38. int lsum[maxn<<],rsum[maxn<<],sum[maxn<<]; //lsum为区间左上升长度,rsum为区间右上升长度,sum为区间最大上升长度。
  39.  
  40. void push_up(int l,int r,int pos)
  41. {
  42. ls[pos] = ls[pos<<];
  43. rs[pos] = rs[pos<<|];
  44. lsum[pos] = lsum[pos<<];
  45. rsum[pos] = rsum[pos<<|];
  46. sum[pos] = max(sum[pos<<],sum[pos<<|]);
  47. int mid = (l + r) >> ;
  48. if (ls[pos<<|] > rs[pos<<])
  49. {
  50. sum[pos] = max(sum[pos],rsum[pos<<] + lsum[pos<<|]);
  51. if (lsum[pos<<] == mid - l + ) //左区间左上升长度已满
  52. lsum[pos] += lsum[pos<<|];
  53. if (rsum[pos<<|] == r - mid) //同理,
  54. rsum[pos] += rsum[pos<<];
  55. }
  56. }
  57.  
  58. void build (int l,int r,int pos)
  59. {
  60. if (l == r)
  61. {
  62. int tmp;
  63. scanf ("%d",&tmp);
  64. ls[pos] = tmp;
  65. rs[pos] = tmp;
  66. lsum[pos] = rsum[pos] = sum[pos] = ;
  67. return;
  68. }
  69. int mid =(l + r) >> ;
  70. build(l,mid,pos<<);
  71. build(mid+,r,pos<<|);
  72. push_up(l,r,pos);
  73. }
  74.  
  75. void update(int l,int r,int pos,int x,int val)
  76. {
  77. if (l == r)
  78. {
  79. ls[pos] = rs[pos] = val;
  80. return;
  81. }
  82. int mid = (l + r) >> ;
  83. if (x <= mid)
  84. update(l,mid,pos<<,x,val);
  85. else
  86. update(mid+,r,pos<<|,x,val);
  87. push_up(l,r,pos);
  88. }
  89.  
  90. int query(int l,int r,int pos,int ua,int ub)
  91. {
  92. if (ua <= l && ub >= r)
  93. {
  94. return sum[pos];
  95. }
  96. int mid = (l + r) >> ;
  97. int ans1 = ,ans2 = ,ans3 = ;
  98. if (ua <= mid)
  99. ans1 = query(l,mid,pos<<,ua,ub);
  100. if (ub > mid)
  101. ans2 = query(mid+,r,pos<<|,ua,ub);
  102. if (ls[pos<<|] > rs[pos<<])
  103. ans3 = min(lsum[pos<<|],ub-mid) + min(rsum[pos<<],mid-ua+);
  104. return max(ans1,max(ans2,ans3));
  105. }
  106.  
  107. int main(void)
  108. {
  109. #ifndef ONLINE_JUDGE
  110. freopen("in.txt","r",stdin);
  111. #endif
  112. int t;
  113. cin>>t;
  114. while (t--)
  115. {
  116. int n,q;
  117. scanf ("%d%d",&n,&q);
  118. build(,n,);
  119. char op[];
  120. int x,y;
  121. for (int i = ; i < q; i++)
  122. {
  123. scanf ("%s%d%d",op,&x,&y);
  124. if (op[] == 'Q')
  125. printf("%d\n",query(,n,,x+,y+));
  126. if (op[] == 'U')
  127. update(,n,,x+,y);
  128. }
  129. }
  130. return ;
  131. }

hdu3308--LCIS 最大连续递增序列长度的更多相关文章

  1. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  2. [Swift]LeetCode674. 最长连续递增序列 | Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  3. LeetCode 最长连续递增序列

    给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...

  4. LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...

  5. leetcode 674. 最长连续递增序列

    1. 题目 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3, ...

  6. LeetCode 674. 最长连续递增序列(Longest Continuous Increasing Subsequence) 18

    674. 最长连续递增序列 674. Longest Continuous Increasing Subsequence 题目描述 给定一个未经排序的整型数组,找到最长且连续的递增序列. Given ...

  7. Leetcode674.Longest Continuous Increasing Subsequence最长连续递增序列

    给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. 尽管 [1,3,5,7] 也 ...

  8. Java实现 LeetCode 674 最长连续递增序列(暴力)

    674. 最长连续递增序列 给定一个未经排序的整数数组,找到最长且连续的的递增序列. 示例 1: 输入: [1,3,5,4,7] 输出: 3 解释: 最长连续递增序列是 [1,3,5], 长度为3. ...

  9. C#LeetCode刷题之#674-最长连续递增序列( Longest Continuous Increasing Subsequence)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3734 访问. 给定一个未经排序的整数数组,找到最长且连续的的递增 ...

随机推荐

  1. [置顶] 白话二分匹配之最大匹配+附上hdu2063解题报告

    最近开始学习图论的二分匹配,关于最大匹配做一次小总结,希望自己后面回头来看一目明了,也对刚接触的人有帮助: ps:开始有的文字很多....对于很多人来说一看到文字就烦啦...不过这个总结是针对匈牙利算 ...

  2. Linux下的bc计算器

    bc = basic calculator scale:设置精度,默认为0 obase:设置输出进制,默认为10 ibase:设置输入进制,默认为10 原文:http://www.linuxidc.c ...

  3. 添加链接服务器 SQL SERVER

    使用sql语句: exec sp_addlinkedserver @server='serverontest',@provider='sqloledb',@srvproduct='',@datasrc ...

  4. HDU4662+无

    把目标中的 U 转化为 I. 又因为 I的个数是有规律的:1 2 4 8 16 ...再结合可以取消 6 12 18 ...个I...得解 #include<string.h> #incl ...

  5. MySQL数据库的环境及简单操作

    ***********************************************声明*************************************************** ...

  6. CH BR8(小学生放假了-clock()/CLOCKS_PER_SEC-斜率优化常错集锦)

    小学生放假了 总时限 26s 内存限制 256MB 出题人 zsyzzsoft 提交情况 16/150 初始分值 1500 锁定情况 背景 我们能见到的最可怕的事情,莫过于小学生放假了! 描述 小学生 ...

  7. .NET基础拾遗(7)多线程开发基础4

    一.多线程编程中的线程同步 1.C#中的lock关键字 lock关键字可能是我们在遇到线程同步的需求时最常用的方式,但lock只是一个语法糖,为什么这么说呢,下面慢慢道来. (1)lock的等效代码其 ...

  8. angularJS环境安装

    第一步: 安装node.js,进入node.js官网(http://nodejs.org/)下载安装相应的node.js版本:

  9. JavaScript随机排序算法1

    1.对数组循环,每一项与随机的某一项位置调换 <ul id="listOne"></ul> <div id="tempOne"&g ...

  10. 【nodejs学习】1.文件操作

    1.小文件拷贝,使用nodejs内置模块 var fs = require('fs'); function copy(src, dst){ fs.writeFileSync(dst, fs.readF ...