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. BZOJ4911: [Sdoi2017]切树游戏

    BZOJ 4911 切树游戏 重构了三次.jpg 每次都把这个问题想简单了.jpg 果然我还是太菜了.jpg 这种题的题解可以一眼秒掉了,FWT+动态DP简直是裸的一批... 那么接下来,考虑如何维护 ...

  2. React-使用Redux-thunk中间件实现ajax数据请求

    把异步函数放在生命周期函数里写,生命周期函数会变得越来越复杂,组件会变得越来越大.Redux默认只处理同步,借助redux-thunk ,可以把异步请求放在actionCreators.js里管理,而 ...

  3. slurmdbd.conf系统初始配置

    # Archive info ArchiveJobs=yes ArchiveDir=/usr/local/globle/softs/slurm/16.05.3/archive/ ArchiveStep ...

  4. ubuntu16.04在GTX1070环境下安装 cuda9.1

    设备要求 系统:Ubuntu16.04 显卡:GTX 1070 驱动:nvidia系列,显卡驱动的版本必须大于等于cuda的sh文件名里面的版本号 驱动可从 此处 下载,我已经整理好了 检查安装驱动 ...

  5. su: 无法设置用户ID: 资源暂时不可用

    登录非root用户,报错如下:[root@test ~]# su - appsu: 无法设置用户ID: 资源暂时不可用 或者用ssh 命令连接服务器之后,如果一段时间不操作,再次进入 Terminal ...

  6. JAVA中使用MD5加密实现密码加密

    1.新建Md5.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 package c ...

  7. Scrum Meeting 8

                第八次会议 No_00:工作情况 No_01:任务说明 待完成 已完成 No_10:燃尽图 No_11:照片记录 待更新 No_100:代码/文档签入记录 No_101:出席表 ...

  8. C# wkhtmltopdf 将html转pdf(详解)

    https://www.cnblogs.com/louby/p/905198.html转自,看文章只放了代码看起来云里雾里的,在此做些解析 使用说明: 1.首先呢,得安装下软件,地址下面有链接,文件里 ...

  9. 语音笔记:CTC

    CTC全称,Connectionist temporal classification,可以理解为基于神经网络的时序类分类.语音识别中声学模型的训练属于监督学习,需要知道每一帧对应的label才能进行 ...

  10. PAT 1046 划拳

    https://pintia.cn/problem-sets/994805260223102976/problems/994805277847568384 划拳是古老中国酒文化的一个有趣的组成部分.酒 ...