题解:

线段树维护区间取min求和求max

维护最小值以及个数,次小值

标记清除时,分情况讨论

当lazy>max1 退出

当max1>lazy>max2(注意不要有等号) 更新

否则递归处理

据吉如一的论文上说是nlogn的复杂度(至今不知论文在何处)

卡常?? 不懂常熟技巧 那就开个o2水一下。。。。

这数的大小 正好2^31 刚开始没看。。对拍挺对交上去wa了

  1. #pragma G++ optimize (2)
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define N 1100000
  6. #define INF 2147483647
  7. #define il inline
  8. struct re{
  9. int max1,max2,num,h,t,lazy;
  10. ll sum;
  11. }p[N*];
  12. ll b[N];
  13. int T,n,m;
  14. il void updata(int x)
  15. {
  16. p[x].sum=p[x*].sum+p[x*+].sum;
  17. p[x].max1=max(p[x*].max1,p[x*+].max1);
  18. if (p[x*].max1==p[x*+].max1)
  19. {
  20. p[x].num=p[x*].num+p[x*+].num;
  21. p[x].max2=max(p[x*].max2,p[x*+].max2);
  22. } else
  23. {
  24. re xx=p[x*],yy=p[x*+];
  25. if (xx.max1<yy.max1) swap(xx,yy);
  26. p[x].num=xx.num;
  27. p[x].max2=max(xx.max2,yy.max1);
  28. }
  29. }
  30. #define mid (h+t)/2
  31. void build(int x,int h,int t)
  32. {
  33. p[x].h=h; p[x].t=t; p[x].lazy=INF;
  34. if (h==t)
  35. {
  36. p[x].max1=b[h],p[x].max2=-INF,p[x].num=;
  37. p[x].sum=b[h];
  38. return;
  39. }
  40. build(x*,h,mid); build(x*+,mid+,t);
  41. updata(x);
  42. }
  43. void down(int x)
  44. {
  45. if (p[x].max1<=p[x].lazy) p[x].lazy=INF;
  46. if (p[x].lazy==INF) return;
  47. if (p[x].h!=p[x].t)
  48. {
  49. if (p[x].lazy<p[x*].lazy) p[x*].lazy=p[x].lazy;
  50. if (p[x].lazy<p[x*+].lazy) p[x*+].lazy=p[x].lazy;
  51. }
  52. if (p[x].max1>p[x].lazy&&p[x].max2<p[x].lazy)
  53. {
  54. p[x].sum=p[x].sum-1ll*(p[x].max1-p[x].lazy)*p[x].num;
  55. p[x].max1=p[x].lazy;
  56. } else
  57. {
  58. down(x*); down(x*+);
  59. updata(x);
  60. }
  61. p[x].lazy=INF;
  62. }
  63. void change(int x,int h,int t,int w)
  64. {
  65. down(x);
  66. if (p[x].h>t||p[x].t<h) return;
  67. if (h<=p[x].h&&p[x].t<=t)
  68. {
  69. p[x].lazy=min(p[x].lazy,w); down(x); return;
  70. }
  71. change(x*,h,t,w); change(x*+,h,t,w);
  72. updata(x);
  73. }
  74. int query1(int x,int h,int t)
  75. {
  76. down(x);
  77. if (p[x].h>t||p[x].t<h) return(-INF);
  78. if (h<=p[x].h&&p[x].t<=t) return(p[x].max1);
  79. return(max(query1(x*,h,t),query1(x*+,h,t)));
  80. }
  81. ll query2(int x,int h,int t)
  82. {
  83. down(x);
  84. if (p[x].h>t||p[x].t<h) return();
  85. if (h<=p[x].h&&p[x].t<=t) return(p[x].sum);
  86. return(query2(x*,h,t)+query2(x*+,h,t));
  87. }
  88. int main()
  89. {
  90. freopen("noip.in","r",stdin);
  91. freopen("noip.out","w",stdout);
  92. std::ios::sync_with_stdio(false);
  93. cin>>T;
  94. for (int ttt=;ttt<=T;ttt++)
  95. {
  96. // clear();
  97. cin>>n>>m;
  98. for (int i=;i<=n;i++) cin>>b[i];
  99. build(,,n);
  100. for (int i=;i<=m;i++)
  101. {
  102. int x,y,z,w;
  103. cin>>x;
  104. if (x==)
  105. {
  106. cin>>y>>z>>w;
  107. change(,y,z,w);
  108. }
  109. if (x==)
  110. {
  111. cin>>y>>z;
  112. cout<<query1(,y,z)<<endl;
  113. }
  114. if (x==)
  115. {
  116. cin>>y>>z;
  117. cout<<query2(,y,z)<<endl;
  118. }
  119. }
  120. }
  121. return ;
  122. }

[HDU] 5306 Gorgeous Sequence [区间取min&求和&求max]的更多相关文章

  1. HDU 5306 Gorgeous Sequence[线段树区间最值操作]

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  2. 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  3. HDU - 5306 Gorgeous Sequence (吉司机线段树)

    题目链接 吉司机线段树裸题... #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3 ...

  4. HDU 5306 Gorgeous Sequence

    如果维护max,sum,那么可以得到一个暴力方法,如果t>=max,那可以return,否则往下更新,显然超时. 在上面基础上,再维护一下次大值,与最大值的个数.这样一来,次大值<t< ...

  5. HDU - 5306 Gorgeous Sequence 线段树 + 均摊分析

    Code: #include<algorithm> #include<cstdio> #include<cstring> #define ll long long ...

  6. HDOJ 5306 Gorgeous Sequence 线段树

    http://www.shuizilong.com/house/archives/hdu-5306-gorgeous-sequence/ Gorgeous Sequence Time Limit: 6 ...

  7. [NOI2005]维修数列 Splay tree 区间反转,修改,求和,求最值

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1500 Description Input 输入文件的第1行包含两个数N和M,N表示初始时数 ...

  8. bzoj 4695: 最假女选手 && Gorgeous Sequence HDU - 5306 && (bzoj5312 冒险 || 小B的序列) && bzoj4355: Play with sequence

    算导: 核算法 给每种操作一个摊还代价(是手工定义的),给数据结构中某些东西一个“信用”值(不是手动定义的,是被动产生的),摊还代价等于实际代价+信用变化量. 当实际代价小于摊还代价时,增加等于差额的 ...

  9. 【hdu5306】 Gorgeous Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5306 (题目链接) 题意 区间取$min$操作,区间求和操作,区间求最值操作. Solution 乱搞一通竟然A ...

随机推荐

  1. mysql alter 用法,修改表,字段等信息

    一: 修改表信息 1.修改表名 alter table test_a rename to sys_app; 2.修改表注释 alter table sys_application comment '系 ...

  2. postgresql时间处理

    时间取到截取 例:select date_trunc('second', "reportTime") from travel_message limit 10; 结果: 他人博客: ...

  3. luogu P4778 Counting swaps

    计数套路题?但是我连套路都不会,,, 拿到这道题我一脸蒙彼,,,感谢@poorpool 大佬的博客的指点 先将第\(i\)位上的数字\(p_i\)向\(i\)连无向边,然后构成了一个有若干环组成的无向 ...

  4. octomap 安装使用

    由于工程实践中需要对机器人地图进行概率化估计并表示,故引入OctoMap库. 本文将介绍如何在Ubuntu环境下安装OctoMap. 如果你安装了ROS,那么一下的安装过程很可能会出错. 首先应该检查 ...

  5. malloc()函数(Linux程序员手册)及函数的正确使用【转】

    转自:https://blog.csdn.net/david_xtd/article/details/7311204 名称 malloc,free,calloc,realloc--分配和释放动态内存 ...

  6. mysql之 innobackupex备份+binlog日志的完全恢复【转】

    前言: MySQL的完全恢复,我们可以借助于完整的 备份+binlog 来将数据库恢复到故障点. 备份可以是热备与逻辑备份(mysqldump),只要备份与binlog是完整的,都可以实现完全恢复. ...

  7. opencv学习笔记(九)Mat 访问图像像素的值

    对图像的像素进行访问,可以实现空间增强,反色,大部分图像特效系列都是基于像素操作的.图像容器Mat是一个矩阵的形式,一般情况下是二维的.单通道灰度图一般存放的是<uchar>类型,其数据存 ...

  8. (并发编程)线程 (理论-创建-lock-属性-守护,与进程的对比)

    一.线程理论1.什么是线程   线程指的是一条流水线的工作过程(执行代码)   进程不是执行单位,是资源单位   一个进程内自带一个线程,线程是执行单位 2.进程VS线程    1.同一进程内的线程们 ...

  9. 转载:2.2.1 块配置项《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19626.html 块配置项由一个块配置项名和一对大括号组成.具体示例如下:events {-} http { upstream ba ...

  10. Ex 5_21 无向图G=(V,E)的反馈边集..._第九次作业

    根据题意,求的是最大生成树.利用Kruskal算法,对边进行从大到小的顺序进行排序,然后再依次取出边加入结果集中.假设图有n个顶点,那么,当结果集中有n-1条边时,剩下的边的集合即为反馈边集. pac ...