序列操作(线段树,模板)
来源:互联网 发布:西科软件 知乎 编辑:程序博客网 时间:2024/06/05 07:45
n个数,m次操作
若a==1,求区间b-c最大值
若a==2,将a[ b ]改为c
#include<iostream>#include<cstdio>#include<algorithm>#include<string>#include<cstring>#define MAXN 200000 using namespace std;int a[MAXN+5],st[MAXN*4+5]; void bulid(int o,int l,int r){ if(l==r) st[o]=a[l]; else { int m=l+((r-l)>>1); bulid((o<<1),l,m); bulid((o<<1)|1,m+1,r); st[o]=max(st[o<<1],st[(o<<1)|1]); }}void exch(int o,int l,int r,int ind,int ans){ if(l==r) { st[o]=ans; return; } else { int m=l+((r-l)>>1); if(ind<=m) { exch((o<<1),l,m,ind,ans);//|1相当于+1 } else { exch((o<<1)|1,m+1,r,ind,ans); } } st[o]=max(st[o<<1],st[(o<<1)|1]);}int sear(int o,int l,int r,int ql,int qr){ if(qr<l||ql>r)return 0; if(qr>=r&&ql<=l)return st[o]; int m=l+((r-l)>>1); return max(sear((o<<1),l,m,ql,qr),sear((o<<1)|1,m+1,r,ql,qr));}int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); bulid(1,1,n); for(int i=1;i<=m;i++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a==1) printf("%d\n",sear(1,1,n,b,c)); else exch(1,1,n,b,c); } return 0;}
1 0
- 序列操作(线段树,模板)
- 序列操作(线段树)
- 【线段树】序列操作
- [BZOJ2962]序列操作(线段树)
- BZOJ1858 序列操作 (线段树)
- 【BZOJ1858】序列操作(SCOI2010)-线段树
- 【SCOI2010】【线段树】序列操作
- 【bzoj2962】【序列操作】【线段树】
- bzoj1858序列操作 线段树
- 【SCOI2010】序列操作 线段树
- bzoj2962 序列操作 线段树
- NEFU 1215 统计序列和 (线段树模板题)
- bzoj 1858: [Scoi2010]序列操作(线段树)
- bzoj 2962: 序列操作 (线段树+数论)
- bzoj1858:序列操作 (线段树区间信息合并)
- [BZOJ 1858][Scoi2010]序列操作(线段树)
- HDU1754(线段树模板题)(没有用懒操作)
- poj 3237 树链剖分模板(用到线段树lazy操作)
- 【Java 教程】
- PAYPAL EC快速支付接入汇总
- 如何使用github管理代码
- 【Abertay阿伯泰大学毕业】
- 解决COM端口号与工具比匹配的问题
- 序列操作(线段树,模板)
- openTSDB+HBase+ZK遇到的坑汇总
- 通过@ImportResource实现xml配置的装载
- Java进阶-----TreeMap
- c++内存的分区
- Retrofit2.0源码分析
- yyyy-MM-dd HH:mm:ss转MM-dd HH:mm,String转String
- 2016-12-23
- rnn