HDU 5306 吉司机线段树
思路:



后面nlogn的部分是伪证...
吉老司机翻车了
//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=;
int cases,n,m,op,xx,yy,zz;
typedef long long ll;
struct SegTree{int max1,max2,maxnum,lazy;ll sum;}tr[N*];
void push_up(int pos){
tr[pos].max2=;int lson=pos<<,rson=pos<<|;
tr[pos].max1=max(tr[lson].max1,tr[rson].max1);
if(tr[lson].max1==tr[rson].max1)
tr[pos].maxnum=tr[lson].maxnum+tr[rson].maxnum,
tr[pos].max1=tr[lson].max1,
tr[pos].max2=max(tr[lson].max2,tr[rson].max2);
else{
tr[lson].max1>tr[rson].max1?tr[pos]=tr[lson]:tr[pos]=tr[rson];
tr[pos].max2=max(tr[lson].max2,tr[rson].max2);
if(tr[pos].max1==tr[lson].max1)tr[pos].max2=max(tr[pos].max2,tr[rson].max1);
else tr[pos].max2=max(tr[pos].max2,tr[lson].max1);
}tr[pos].sum=tr[lson].sum+tr[rson].sum;
}
void change(int pos,int wei){
tr[pos].sum-=(1ll*tr[pos].max1-wei)*tr[pos].maxnum;
tr[pos].max1=tr[pos].lazy=wei;
}
void push_down(int pos){
int lson=pos<<,rson=pos<<|;
if(tr[lson].max1>tr[pos].lazy)change(lson,tr[pos].lazy),tr[lson].lazy=tr[pos].lazy;
if(tr[rson].max1>tr[pos].lazy)change(rson,tr[pos].lazy),tr[rson].lazy=tr[pos].lazy;
tr[pos].lazy=-;
}
void build(int l,int r,int pos){
tr[pos].lazy=-,tr[pos].max2=;
if(l==r){scanf("%d",&tr[pos].max1),tr[pos].sum=tr[pos].max1,tr[pos].maxnum=;return;}
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
build(l,mid,lson),build(mid+,r,rson),push_up(pos);
}
void insert(int l,int r,int pos,int L,int R,int wei){
if(~tr[pos].lazy)push_down(pos);
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
if(l>=L&&r<=R){
if(wei>=tr[pos].max1)return;
else if(wei<tr[pos].max1&&wei>tr[pos].max2){change(pos,wei);return;}
else insert(l,mid,lson,L,R,wei),insert(mid+,r,rson,L,R,wei);
}
if(mid<L)insert(mid+,r,rson,L,R,wei);
else if(mid>=R)insert(l,mid,lson,L,R,wei);
else insert(l,mid,lson,L,R,wei),insert(mid+,r,rson,L,R,wei);
push_up(pos);
}
ll query_sum(int l,int r,int pos,int L,int R){
if(~tr[pos].lazy)push_down(pos);
if(l>=L&&r<=R)return tr[pos].sum;
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
if(mid<L)return query_sum(mid+,r,rson,L,R);
else if(mid>=R)return query_sum(l,mid,lson,L,R);
else return query_sum(l,mid,lson,L,R)+query_sum(mid+,r,rson,L,R);
}
int query_max(int l,int r,int pos,int L,int R){
if(~tr[pos].lazy)push_down(pos);
if(l>=L&&r<=R)return tr[pos].max1;
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
if(mid<L)return query_max(mid+,r,rson,L,R);
else if(mid>=R)return query_max(l,mid,lson,L,R);
else return max(query_max(l,mid,lson,L,R),query_max(mid+,r,rson,L,R));
}
int read(){
char p=getchar();int x=;
while(p<''||p>'')p=getchar();
while(p>=''&&p<='')x=x*+p-'',p=getchar();
return x;
}
signed main(){
scanf("%d",&cases);
while(cases--){
n=read(),m=read(),build(,n,);
for(int i=;i<=m;i++){
op=read(),xx=read(),yy=read();
if(!op)zz=read(),insert(,n,,xx,yy,zz);
else if(op==)printf("%d\n",query_max(,n,,xx,yy));
else printf("%lld\n",query_sum(,n,,xx,yy));
}
}
}
HDU 5306 吉司机线段树的更多相关文章
- HDU - 6315 吉司机线段树
题意:给出a,b数组,区间上两种操作,给\(a[L,R]\)+1s,或者求\(\sum_{i=l}^{r}a_i/b_i\) 一看就知道是吉司机乱搞型线段树(低配版),暴力剪枝就好 维护区间a的最大值 ...
- HDU - 5306 Gorgeous Sequence (吉司机线段树)
题目链接 吉司机线段树裸题... #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3 ...
- UVALive - 4108 SKYLINE (吉司机线段树)
题目链接 题意:在一条直线上依次建造n座建筑物,每座建筑物建造完成后询问它在多长的部分是最高的. 比较好想的方法是用线段树分别维护每个区间的最小值mi和最大值mx,当建造一座高度为x的建筑物时,若mi ...
- BZOJ4355: Play with sequence(吉司机线段树)
题意 题目链接 Sol 传说中的吉司机线段树??感觉和BZOJ冒险那题差不多,就是强行剪枝... 这题最坑的地方在于对于操作1,$C >= 0$, 操作2中需要对0取max,$a[i] > ...
- bzoj4355 Play with sequence(吉司机线段树)题解
题意: 已知\(n\)个数字,进行以下操作: \(1.\)区间\([L,R]\) 赋值为\(x\) \(2.\)区间\([L,R]\) 赋值为\(max(a[i] + x, 0)\) \(3.\)区间 ...
- bzoj5312 冒险(吉司机线段树)题解
题意: 已知\(n\)个数字,进行以下操作: \(1.\)区间\([L,R]\) 按位与\(x\) \(2.\)区间\([L,R]\) 按位或\(x\) \(3.\)区间\([L,R]\) 询问最大值 ...
- bzoj4695 最假女选手(势能线段树/吉司机线段树)题解
题意: 已知\(n\)个数字,进行以下操作: \(1.\)给一个区间\([L,R]\) 加上一个数\(x\) \(2.\)把一个区间\([L,R]\) 里小于\(x\) 的数变成\(x\) \(3.\ ...
- hdu6521 吉司机线段树
http://acm.hdu.edu.cn/showproblem.php?pid=6521 待填 代码 #include<bits/stdc++.h> #define ls o<& ...
- HDU 5306 Gorgeous Sequence[线段树区间最值操作]
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
随机推荐
- Greek symbols --Latex
$\propto$ \propto $\infty$ \infty $\ne$ \ne $\approx$ \approx $\sim$ : \sim --- same ...
- PAT 1145 Hashing - Average Search Time
The task of this problem is simple: insert a sequence of distinct positive integers into a hash tabl ...
- jquery ajax报Uncaught TypeError :Illegal invocation
使用jquery ajax异步提交的时候报Uncaught TypeError :Illegal invocation错误,报错信息如图: 上网查了一下jquery的这个错误,导致这个错误的原因有俩点 ...
- 实用型的DJANGO ORM
比较深入一点的内容,需要用时,用心看看. URL: https://www.sitepoint.com/doing-more-with-your-django-models/ https://www. ...
- JavaSE部分之(1)Java基础
JavaSE部分之(1)Java基础 1.为什么重写equals还要重写hashcode 为了提高程序的效率才实现了hashcode方法,先进行hashcode的比较,如果不同,那就没必要再进行equ ...
- Hive之单独部署机器
环境说明 CentOS7,hadoop-2.6.5,hive-1.2.2,MariaDB-5.5.60,jdk-1.8 假设hive机已经安装好了MariaDB(已启动且已创建好hive账号,对hiv ...
- MAPZONE GIS SDK接入Openlayers3之二——空间参考扩展
Openlayers默认了两种空间参考,一个是EPSG4326,一个是EPSG3857,其它的空间参考需要进行扩展才能使用.所以我们初始化时进行了如下操作: 1.将配置数据库中所有的空间参考读取出来, ...
- PHP中错误与异常的日志记录用法分析
原文:http://www.jb51.net/article/89548.htm ----------------------------------------------------------- ...
- ASPNETCOREAPI 跨域处理 SQL 语句拼接 多条件分页查询 ASPNET CORE 核心 通过依赖注入(注入服务)
ASPNETCOREAPI 跨域处理 AspNetCoreApi 跨域处理 如果咱们有处理过MV5 跨域问题这个问题也不大. (1)为什么会出现跨域问题: 浏览器安全限制了前端脚本跨站点的访问资源, ...
- smart pointer
smart pointer是一种abstract data type,它可以模仿指针的行为,而且额外提供了一系列诸如自己主动内存管理.边界检查等特性,这些特性是为了在保证效率的基础上降低因为对指针的不 ...