hdu5306 Gorgeous Sequence

题目大意

​ 给你一个序列,维护区间和,区间chkmin和区间最大值

数据范围

数据组数T,序列长度n,操作次数m

$T = 100,\sum n \leqslant 1000000 ,\sum m \leqslant 1000000 $

这是一道吉司机线段树的裸题,直接维护区间最大值,次大值,最大值个数,区间和就行了。

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
int x;
char c;
int f=1;
while((c=getchar())!='-' && (c<'0' || c>'9'));
if(c=='-') c=getchar(),f=-1;
x=c^'0';
while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
return x*f;
}
inline ll readll(){
ll x;
char c;
ll f=1;
while((c=getchar())!='-' && (c<'0' || c>'9'));
if(c=='-') c=getchar(),f=-1;
x=c^'0';
while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
return x*f;
}
inline bool chkmax(int &x,int y){return (y>x)?(x=y,1):0;}
inline bool chkmin(int &x,int y){return (y<x)?(x=y,1):0;}
const int maxn=1e6+10;
struct Segment_tree{
int Max[maxn<<2],Sec[maxn<<2],tot[maxn<<2],tag[maxn<<2];
ll sum[maxn<<2];
void push_up(int x){
sum[x]=sum[x<<1]+sum[x<<1|1];
Max[x]=Max[x<<1],tot[x]=tot[x<<1],Sec[x]=max(Sec[x<<1],Sec[x<<1|1]);
if(chkmax(Max[x],Max[x<<1|1])) tot[x]=tot[x<<1|1],chkmax(Sec[x],Max[x<<1]);
else if(Max[x]==Max[x<<1|1]) tot[x]+=tot[x<<1|1];
else chkmax(Sec[x],Max[x<<1|1]);
}
void change(int x,int v){
if(Max[x]<=v) return;
sum[x]-=1ll*(Max[x]-v)*tot[x];
Max[x]=tag[x]=v;
}
void push_down(int x){
if(tag[x]==-1) return;
change(x<<1,tag[x]);
change(x<<1|1,tag[x]);
tag[x]=-1;
}
void build_tree(int x,int L,int R){
tag[x]=-1;
if(L==R){
Max[x]=read();tot[x]=1;
Sec[x]=0;sum[x]=Max[x];
return;
}
int Mid=(L+R)>>1;
build_tree(x<<1,L,Mid);
build_tree(x<<1|1,Mid+1,R);
push_up(x);
}
void update(int x,int L,int R,int ql,int qr,int v){
if(Max[x]<=v) return;
if(ql<=L && R<=qr && Sec[x]<v){
change(x,v);
return;
}
int Mid=(L+R)>>1;
push_down(x);
if(ql<=Mid) update(x<<1,L,Mid,ql,qr,v);
if(qr>Mid) update(x<<1|1,Mid+1,R,ql,qr,v);
push_up(x);
}
int query_Max(int x,int L,int R,int ql,int qr){
if(ql<=L && R<=qr) return Max[x];
push_down(x);
int Mid=(L+R)>>1,res=0;
if(ql<=Mid) res=query_Max(x<<1,L,Mid,ql,qr);
if(qr>Mid) chkmax(res,query_Max(x<<1|1,Mid+1,R,ql,qr));
push_up(x);
return res;
}
ll query_sum(int x,int L,int R,int ql,int qr){
if(ql<=L && R<=qr) return sum[x];
push_down(x);
int Mid=(L+R)>>1;
ll res=0;
if(ql<=Mid) res=query_sum(x<<1,L,Mid,ql,qr);
if(qr>Mid) res+=query_sum(x<<1|1,Mid+1,R,ql,qr);
push_up(x);
return res;
}
}Seg;
int main(){
#ifndef ONLINE_JUDGE
freopen("segment.in","r",stdin);
freopen("segment.out","w",stdout);
#endif
int T=read();
while(T--){
int n=read(),m=read();
Seg.build_tree(1,1,n);
while(m--){
int ty=read(),l=read(),r=read();
if(ty==0){
int x=read();
Seg.update(1,1,n,l,r,x);
}
else if(ty==1) printf("%d\n",Seg.query_Max(1,1,n,l,r));
else printf("%lld\n",Seg.query_sum(1,1,n,l,r));
}
}
return 0;
}

hdu5306 Gorgeous Sequence的更多相关文章

  1. AHOI2014 奇怪的计算器 和 HDU5306 Gorgeous Sequence

    线段树秀操作题. 奇怪的计算器 有 N 个数,一共会对这 N 个数执行 M 个指令(对没个数执行的指令都一样),每一条指令可以是以下四种指令之一:(这里 a 表示一个正整数) 加上 a 减去 a 乘以 ...

  2. [HDU5306]Gorgeous Sequence(标记回收线段树)

    题意:维护一个序列,支持区间与一个数取min,询问区间最大,询问区间和(序列长度<=1e6) 分析: http://www.shuizilong.com/house/archives/hdu-5 ...

  3. HDU 5306 Gorgeous Sequence[线段树区间最值操作]

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  4. 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 ...

  5. HDOJ 5306 Gorgeous Sequence 线段树

    http://www.shuizilong.com/house/archives/hdu-5306-gorgeous-sequence/ Gorgeous Sequence Time Limit: 6 ...

  6. Gorgeous Sequence(线段树)

    Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  7. 【hdu5306】 Gorgeous Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5306 (题目链接) 题意 区间取$min$操作,区间求和操作,区间求最值操作. Solution 乱搞一通竟然A ...

  8. 【hdu5306】Gorgeous Sequence 线段树区间最值操作

    题目描述 给你一个序列,支持三种操作: $0\ x\ y\ t$ :将 $[x,y]$ 内大于 $t$ 的数变为 $t$ :$1\ x\ y$ :求 $[x,y]$ 内所有数的最大值:$2\ x\ y ...

  9. HDU5306:Gorgeous Sequence——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=5306 给一个数组,m次操作: 1:l r x,将a[i](l<=i<=r)=min(a[i],x) ...

随机推荐

  1. 新页面,简单的tree视图写法

    .xml文件 <?xml version="1.0"?><openerp> <data> <!--Tree view--> < ...

  2. ASP.NET Core如何设置请求超时时间

    如果一个请求在ASP.NET Core中运行太久,会导致请求超时,目前ASP.NET Core对请求超时的设置比较麻烦,本文列出目前收集到的一些方法,供大家参考. 部署ASP.NET Core到IIS ...

  3. 读取Excel的记录并导入SQL数据库

    准备一下,近段时间,需要把Excel的数据导入数据库中. 引用命名空间: using System.Configuration; using System.Data; using System.Dat ...

  4. EZ 2018 06 17 NOIP2018 模拟赛(十九)

    这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...

  5. eclipse取消自动输入提示

    在设置Eclipse自动提示后,按a-z都会显示提示,但是我们需要键入Enter才会输入,而默认的所有都键入,非常弱智,可采用下面方法设置. 1,先找到相关的插件: window -> show ...

  6. Effective C++学习笔记之#define

    前言 条款02:尽量以const.enum.inline替换#define:尽可能用编译器代替不必要的预处理器. 内容 一.对于单纯常量 1.const 有两种特殊的const,常量指针和class专 ...

  7. 记一次用WPScan辅助渗透WordPress站点

    记一次用WPScan辅助渗透WordPress站点 一.什么是WPScan? WPScan 是一个扫描 WordPress 漏洞的黑盒子扫描器,它可以为所有 Web 开发人员扫描 WordPress ...

  8. 记一次拿webshell踩过的坑(如何用PHP编写一个不包含数字和字母的后门)

    0x01 前言 最近在做代码审计的工作中遇到了一个难题,题目描述如下: <?php include 'flag.php'; if(isset($_GET['code'])){ $code = $ ...

  9. Centos7系统下修改主机名操作笔记

    习惯了在Centos6系统下修改主机名的操作,但是Centos7下修改主机名的操作却大不相同!操作笔记如下: 在CentOS中,有三种定义的主机名:静态的(static),瞬态的(transient) ...

  10. db2修改最大连接数

    查看当前连接数,sample为数据库名db2 list applications for db sample db2 list applications for db sample show deta ...