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 ...
随机推荐
- python下载网络文件
python下载网络文件 制作人:全心全意 下载图片 #!/usr/bin/python #-*- coding: utf-8 -*- import requests url = "http ...
- buf.writeUInt32BE()
buf.writeUInt32BE(value, offset[, noAssert]) buf.writeUInt32LE(value, offset[, noAssert]) value {Num ...
- chrome://plugins 无法打开的解决方法,同时解决“该网页已屏蔽插件-adobe flash player”
chrome打开想要看视频时提示该网页已屏蔽插件-adobe flash player,在网上查了半天说在chrome plugins里面打开就可以了.可是chrome://plugins 无法打开, ...
- Python基础之生成器、迭代器
一.字符串格式化进阶 Python的字符串格式化有两种方式: 百分号方式.format方式,由于百分号的方式相对来说比较老,在社区里讨论format方式有望取代百分号方式,下面我们分别介绍一下这两种方 ...
- CentOS6网络设置(桥接模式)&Xshell连接虚拟机-
CentOS无法上网,且Xshell无法连接到虚拟机问题: 目的:在桥接模式下,CentOS能上网,且Xshell能够连接到虚拟机.解决办法:https://www.youtube.com/watch ...
- M - Help Jimmy DP
"Help Jimmy" 是在下图所示的场景上完成的游戏. 场景中包括多个长度和高度各不相同的平台.地面是最低的平台,高度为零,长度无限. Jimmy老鼠在时刻0从高于所有平台的某 ...
- kendo grid 点击更新没有反映
因为没有在dataSource上写schema schema: { model: { id: "DeptId", fields: { CompanyId: { editable: ...
- Portal嵌入SAPUI5应用程序
Embedding SAPUI5 Applications You can embed SAPUI5 applications directly into the SAP Fiori launchpa ...
- 函数式语言(functional language)定义、函数式语言的种类以及为什么函数式语言会流行起来的学习笔记
一.什么是函数式语言? 函数式语言一类程序设计语言,是一种非冯·诺伊曼式的程序设计语言.函数式语言主要成分是原始函数.定义函数和函数型.这种语言具有较强的组织数据结构的能力,可以把某一数据 ...
- 《WF in 24 Hours》读书笔记 - Hour 3(1) - Workflow:添加宿主和事件监听
1. 创建项目组,并添加一个Console Project和Activity Library,在Activity Library的项目中添加CodeActivity1和CodeActivity2,最终 ...