题解:

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

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

标记清除时,分情况讨论

当lazy>max1 退出

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

否则递归处理

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

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

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

#pragma G++ optimize (2)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1100000
#define INF 2147483647
#define il inline
struct re{
int max1,max2,num,h,t,lazy;
ll sum;
}p[N*];
ll b[N];
int T,n,m;
il void updata(int x)
{
p[x].sum=p[x*].sum+p[x*+].sum;
p[x].max1=max(p[x*].max1,p[x*+].max1);
if (p[x*].max1==p[x*+].max1)
{
p[x].num=p[x*].num+p[x*+].num;
p[x].max2=max(p[x*].max2,p[x*+].max2);
} else
{
re xx=p[x*],yy=p[x*+];
if (xx.max1<yy.max1) swap(xx,yy);
p[x].num=xx.num;
p[x].max2=max(xx.max2,yy.max1);
}
}
#define mid (h+t)/2
void build(int x,int h,int t)
{
p[x].h=h; p[x].t=t; p[x].lazy=INF;
if (h==t)
{
p[x].max1=b[h],p[x].max2=-INF,p[x].num=;
p[x].sum=b[h];
return;
}
build(x*,h,mid); build(x*+,mid+,t);
updata(x);
}
void down(int x)
{
if (p[x].max1<=p[x].lazy) p[x].lazy=INF;
if (p[x].lazy==INF) return;
if (p[x].h!=p[x].t)
{
if (p[x].lazy<p[x*].lazy) p[x*].lazy=p[x].lazy;
if (p[x].lazy<p[x*+].lazy) p[x*+].lazy=p[x].lazy;
}
if (p[x].max1>p[x].lazy&&p[x].max2<p[x].lazy)
{
p[x].sum=p[x].sum-1ll*(p[x].max1-p[x].lazy)*p[x].num;
p[x].max1=p[x].lazy;
} else
{
down(x*); down(x*+);
updata(x);
}
p[x].lazy=INF;
}
void change(int x,int h,int t,int w)
{
down(x);
if (p[x].h>t||p[x].t<h) return;
if (h<=p[x].h&&p[x].t<=t)
{
p[x].lazy=min(p[x].lazy,w); down(x); return;
}
change(x*,h,t,w); change(x*+,h,t,w);
updata(x);
}
int query1(int x,int h,int t)
{
down(x);
if (p[x].h>t||p[x].t<h) return(-INF);
if (h<=p[x].h&&p[x].t<=t) return(p[x].max1);
return(max(query1(x*,h,t),query1(x*+,h,t)));
}
ll query2(int x,int h,int t)
{
down(x);
if (p[x].h>t||p[x].t<h) return();
if (h<=p[x].h&&p[x].t<=t) return(p[x].sum);
return(query2(x*,h,t)+query2(x*+,h,t));
}
int main()
{
freopen("noip.in","r",stdin);
freopen("noip.out","w",stdout);
std::ios::sync_with_stdio(false);
cin>>T;
for (int ttt=;ttt<=T;ttt++)
{
// clear();
cin>>n>>m;
for (int i=;i<=n;i++) cin>>b[i];
build(,,n);
for (int i=;i<=m;i++)
{
int x,y,z,w;
cin>>x;
if (x==)
{
cin>>y>>z>>w;
change(,y,z,w);
}
if (x==)
{
cin>>y>>z;
cout<<query1(,y,z)<<endl;
}
if (x==)
{
cin>>y>>z;
cout<<query2(,y,z)<<endl;
}
}
}
return ;
}

[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. 图标网站,IcoMoon,自己动手做一个 font

    很有用的IcoMoon,在线制作工工具:https://icomoon.io/app/#/select/font 大神解说:如何灵活利用免费开源图标字体-IcoMoon篇http://www.zhan ...

  2. Keil4 几例异常解决办法

    以下几个问题在Keil5上没有发现,不过因为下载的例子都是Keil4,强迫症让我用起了Keil4 错误一:main.c: Warning: C3910W: Old syntax, please use ...

  3. [CQOI2012]组装 (贪心)

    CQOI2012]组装 solution: 蒟蒻表示并不会模拟退火,所以用了差分数组加贪心吗.我们先来看题: 在数轴上的某个位置修建一个组装车间 到组装车间距离的平方的最小值. 1<=n< ...

  4. 使用CSS将图像对齐

    相对于<img>元素的align特性来说,越来越多的网页设计人员使用float属性来对齐图像.可以采用两种方式来实现对齐.为了确保文本不会与图像的边缘接触,我们经常会给图像增加一个外边距. ...

  5. 2018-2019-2 网络对抗技术 20165230 Exp5 MSF基础应用

    目录 1.实验内容 2.基础问题回答 3.实验内容 任务一:一个主动攻击实践 漏洞MS08_067(成功) 任务二:一个针对浏览器的攻击 ms11_050(成功) ms14_064(成功) 任务三:一 ...

  6. 单页应用 WebApp SPA 骨架 框架 路由 页面切换 转场

    这里收录三个同类产品,找到他们花了我不少时间呢. 张鑫旭写的mobilebone自述:mobile移动端,PC桌面端页面无刷新过场JS骨架,简单.专注!http://www.zhangxinxu.co ...

  7. /etc/my.cnf

    [client] default-character-set=utf8 [mysqld] tmp_table_size = 2048M max_heap_table_size = 2048M max_ ...

  8. jvm系列三、java GC算法 垃圾收集器

    原文链接:http://www.cnblogs.com/ityouknow/p/5614961.html 概述 垃圾收集 Garbage Collection 通常被称为“GC”,它诞生于1960年 ...

  9. dubbo系列七、dubbo @Activate 注解使用和实现解析

    一.用法 Activate注解表示一个扩展是否被激活(使用),可以放在类定义和方法上,dubbo用它在spi扩展类定义上,表示这个扩展实现激活条件和时机. @Activate(group = Cons ...

  10. python模块介绍- binascii:二进制和ASCII互转以及其他进制转换

    20.1 binascii:二进制和ASCII互转作用:二进制和ASCII互相转换. Python版本:1.5及以后版本 binascii模块包含很多在二进制和ASCII编码的二进制表示转换的方法.通 ...