[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 ...
随机推荐
- python -- 算法
给定四个数字,找出不重复的排列组合可能 # 黑魔法方法,还纳闷 lambda 不能 yield 其实把 [] 改为小括号即是生成器啦 func = lambda num_tuple:((i,j,k,n ...
- bzoj4802 欧拉函数(附Millar-Rabin和Pollard-Rho讲解)
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4802 [题解] 参考:http://www.matrix67.com/blog/archiv ...
- 高版本sonar安装遇到的坑-sonar 6.6
最近安装了6.6版本的sonar,发现里面的坑还是很多,下面列举下遇到的坑 sonar插件地址:https://docs.sonarqube.org/display/PLUG/Plugin+Libra ...
- UE4中Component和Subobject的区别
Component是Subobject的一种. 其中, Subobject是一种Outer不是一个UPackage的UObject,而UPackage是整个层次结构中的最上层,指向磁盘上的一个.uas ...
- vue axios全攻略
不再继续维护vue-resource,并推荐大家使用 axios 开始,axios 被越来越多的人所了解.本来想在网上找找详细攻略,突然发现,axios 的官方文档本身就非常详细!!有这个还要什么自行 ...
- Java9都快发布了,Java8的十大新特性你了解多少呢?
Java 9预计将于今年9月份发布,这是否会是一次里程碑式的版本,我们拭目以待.今天,我们先来复习一下2014年发布的Java 8的十大新特性. Java 8可谓是自Java 5以来最具革命性的版本了 ...
- Java调整JVM内存大小——(八)
JVM内存大小是有限的,有的时候程序过大时候会导致超出最大内存,产生下面异常: Exception in thread "main" java.lang.OutOfMemoryEr ...
- 使用Groovy的sql模块操作mysql进行多种查询
连接数据库,这里要创建一个sql实例来操作数据库,必须加载jdbc驱动包,使用两个注解,否则会报错: import groovy.sql.Sql url='jdbc:mysql://localhost ...
- C++学习5-面向对象编程基础(构造函数、转换构造、静态数据成员、静态成员函数、友元)
知识点学习 类 const作用 C语言的const限定符的含义为"一个不能改变值的变量",C++的const限定符的含义为"一个有类型描述的常量": const ...
- eclipse自定义工具栏
设置:1.Window2.Customize Perspective说明:Tool Bar Visibility定义菜单栏,Shortcuts定义右键new菜单