Spoj 1716 Can you answer these queries III
来源:互联网 发布:matlab 四维矩阵 画图 编辑:程序博客网 时间:2024/05/19 16:23
和Spoj 1716 Can you answer these queries I一个题意
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long LL;const LL INF = 0x3f3f3f3f3f3f3f3fll;const int maxn = 50000+10;#define Now int now,int l,int r#define Mid int mid = (l+r)>>1#define lson now<<1,l,mid#define rson now<<1|1,mid+1,r#define root 1,1,Nint N,M;struct Info{LL Data_lmax,Data_rmax,Data_max,Data_sum;void maintain(LL x){Data_lmax = Data_rmax = Data_max = Data_sum = x;}Info(){maintain(-INF);Data_sum = 0;}};Info operator + (const Info & a,const Info & b){Info ret;ret.Data_sum = a.Data_sum+b.Data_sum;ret.Data_lmax = max(a.Data_lmax,a.Data_sum+b.Data_lmax);ret.Data_rmax = max(b.Data_rmax,a.Data_rmax+b.Data_sum);ret.Data_max = max(max(a.Data_max,b.Data_max),a.Data_rmax+b.Data_lmax);return ret;}Info Nodes[maxn<<2]; void update(Now,int pos,LL val){ if(l == r){ Nodes[now].maintain(val); return; } Mid; if(pos <= mid) update(lson,pos,val); else update(rson,pos,val); Nodes[now] = Nodes[now<<1]+Nodes[now<<1|1]; } Info query(Now,int ql,int qr){ if(ql <= l && r <= qr){ return Nodes[now]; } Mid; Info ret; if(ql <= mid) ret = ret + query(lson,ql,qr); if(qr > mid) ret = ret + query(rson,ql,qr); return ret; }int main(){int op;scanf("%d",&N);LL x;for(int i = 1; i <= N; i++){scanf("%lld",&x);update(root,i,x);}scanf("%d",&M);while(M--){scanf("%d",&op);if(op){int ql,qr;scanf("%d %d",&ql,&qr);printf("%lld\n",query(root,ql,qr).Data_max);}else{int pos;LL x;scanf("%d %lld",&pos,&x);update(root,pos,x);}}return 0;}
阅读全文
0 0
- 【SPOJ】1716 Can you answer these queries III 线段树
- 【线段树】 SPOJ 1716 Can you answer these queries III
- Spoj 1716 Can you answer these queries III
- spoj 1716 Can you answer these queries III
- Spoj 1716 Can you answer these queries III
- SPOJ/GSS3:Can you answer these queries III(线段树)
- spoj 1716. Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- spoj 1716. Can you answer these queries III(线段树)
- SPOJ GSS3 Can you answer these queries III (线段树)
- 【SPOJ】Can you answer these queries III【线段树】
- [SPOJ GSS3] Can you answer these queries III [线段树]
- SPOJ GSS3 Can you answer these queries III
- SPOJ GSS3 Can you answer these queries III
- 深度学习来做图像分割 Fully Convolutional Networks for Semantic Segmentation (FCNs)
- codeforce_314D Sereja and Periods (动态规划)
- 一些讲RNN-lstm比较好的博客
- 注解学习
- Hilbert曲线介绍以及代码实现
- Spoj 1716 Can you answer these queries III
- css属性之定位
- Oracle 数据库
- eclipse-tomcatplugin部署maven项目方式八
- 计数排序
- 【大话数据结构】树和二叉树
- day03 伪列:
- Spring配置连接池和dao使用jdbcTemplate
- RxJava 1.x 业务逻辑的组织