[HDU] 5306 Gorgeous Sequence [区间取min&求和&求max]
题解:
线段树维护区间取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]的更多相关文章
- HDU 5306 Gorgeous Sequence[线段树区间最值操作]
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- 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 ...
- HDU - 5306 Gorgeous Sequence (吉司机线段树)
题目链接 吉司机线段树裸题... #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3 ...
- HDU 5306 Gorgeous Sequence
如果维护max,sum,那么可以得到一个暴力方法,如果t>=max,那可以return,否则往下更新,显然超时. 在上面基础上,再维护一下次大值,与最大值的个数.这样一来,次大值<t< ...
- HDU - 5306 Gorgeous Sequence 线段树 + 均摊分析
Code: #include<algorithm> #include<cstdio> #include<cstring> #define ll long long ...
- HDOJ 5306 Gorgeous Sequence 线段树
http://www.shuizilong.com/house/archives/hdu-5306-gorgeous-sequence/ Gorgeous Sequence Time Limit: 6 ...
- [NOI2005]维修数列 Splay tree 区间反转,修改,求和,求最值
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1500 Description Input 输入文件的第1行包含两个数N和M,N表示初始时数 ...
- bzoj 4695: 最假女选手 && Gorgeous Sequence HDU - 5306 && (bzoj5312 冒险 || 小B的序列) && bzoj4355: Play with sequence
算导: 核算法 给每种操作一个摊还代价(是手工定义的),给数据结构中某些东西一个“信用”值(不是手动定义的,是被动产生的),摊还代价等于实际代价+信用变化量. 当实际代价小于摊还代价时,增加等于差额的 ...
- 【hdu5306】 Gorgeous Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5306 (题目链接) 题意 区间取$min$操作,区间求和操作,区间求最值操作. Solution 乱搞一通竟然A ...
随机推荐
- 动态生成js数据Response.Expires=1440竟然无效?
项目当中有一些数据,比如多语言翻译,要求做语言包,起初当然是做成i18n.js文件,但是每个阶段版本更新都会增加一些key,那么发布的时候只能给<script>的src增加?2018091 ...
- linux 命令收集 阿里云nginx升级等 查看磁盘空间 版本等
—————————————————— 查磁盘 df -h此命令直观的呈现出磁盘大小有多少Gdf -hl文件系统 容量 已用 可用 已用% 挂载点/dev/hdb2 75G 75G 0 100% /就是 ...
- JS简史
一.产生背景 1)在JavaScript问世之前,必须把表单数据发送到服务器端才能确定用户是否没有填写某个必填域,是否输入了无效的值: 2)为完成简单的表单验证而频繁地与服务器交换数据只会加重用户的负 ...
- Linux - 进程服务资源
1.进程查看操作管理 ps -eaf # 查看所有进程 kill - PID # 强制终止某个PID进程 kill - PID # 安全退出 需程序内部处理信号 cmd & # 命令后台运行 ...
- luogu P2480 [SDOI2010]古代猪文
M_sea:这道题你分析完后就是一堆板子 废话 理解完题意后,我们要求的东西是\(G^s(s=\sum_{d|n} \binom{n}{d})\) 但是这个指数\(s\)算出来非常大,,, 我们可以利 ...
- 以前的 Delphi版本
Delphi 1 Delphi 2 Delphi 3 Delphi 4 Delphi 5 Delphi 6 Delphi 7 Delphi 8 Delphi 2005
- Struts的JSON机制
需要加入jar包 Struts的JSON帮助我们自动将对象解析为JSON对象,不用我门借助第三方进行JSON的解析 .具体的使用机制如下: 1.Action类 package StrutsJSON; ...
- python之模块array
>>> import array#定义了一种序列数据结构 >>> help(array) #创建数组,相当于初始化一个数组,如:d={},k=[]等等 array( ...
- 【转】Python中的字符串与字符编码
[转]Python中的字符串与字符编码 本节内容: 前言 相关概念 Python中的默认编码 Python2与Python3中对字符串的支持 字符编码转换 一.前言 Python中的字符编码是个老生常 ...
- STM32F103X datasheet学习笔记---DMA
1.前言 直接存储器存取(DMA)用来提供在外设和存储器之间或者存储器和存储器之间的高速数据传输. 无须CPU干预,数据可以通过DMA快速地移动,这就节省了CPU的资源来做其他操作. 两个DMA控制器 ...