博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj_3468,线段树成段更新
阅读量:7070 次
发布时间:2019-06-28

本文共 1096 字,大约阅读时间需要 3 分钟。

参考自http://www.notonlysuccess.com/index.php/segment-tree-complete/
#include
#include
#include
#include
#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;const int maxn=111111;long long sum[maxn<<2];long long col[maxn<<2];void pushUp(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void pushDown(int rt,int m){ if(col[rt]) { col[rt<<1]+=col[rt]; col[rt<<1|1]+=col[rt]; sum[rt<<1]+=col[rt]*(m-(m>>1)); sum[rt<<1|1]+=col[rt]*(m>>1); col[rt]=0; }}void build(int l,int r,int rt){ col[rt]=0; if(r==l) { scanf("%lld",&sum[rt]); return ; } int m=(r+l)>>1; build(lson); build(rson); pushUp(rt);}void update(int L,int R,int d,int l,int r,int rt){ if(L<=l&&r<=R) { sum[rt]+=d*(r-l+1); col[rt]+=d; return; } pushDown(rt,r-l+1); int m=(l+r)>>1; if(L<=m) update(L,R,d,lson); if(m
>1; if(L<=m) ret+=query(L,R,lson); if(m

转载于:https://www.cnblogs.com/vactor/p/4099982.html

你可能感兴趣的文章
为每一个table单元格设置不同的背景颜色
查看>>
盘点智能硬件中那些脑洞大开的黑科技
查看>>
[HDFS Manual] CH4 HDFS High Availability Using the Quorum Journal Manager
查看>>
maven pom.xml详解
查看>>
活动目录数据库文件介绍
查看>>
Linux下配置tomcat+apr+native应对高并发
查看>>
html5播放mp4视频代码
查看>>
孟子>正文 活动目录(Active Directory)域故障解决实例(转载)
查看>>
NoSuchMethodError: org.hibernate.SessionFactory.openSession
查看>>
textarea自动调整高宽
查看>>
python基础---面向对象高级
查看>>
vim的分屏
查看>>
windows客户端安装
查看>>
关于大型网站技术演进的思考(十八)--网站静态化处理—反向代理(10)
查看>>
Centos7怎么安装gnome桌面及远程桌面VNC
查看>>
mount挂载报错mount:you must specify the filesystem type
查看>>
yaf 模块与控制器
查看>>
Python 模块调用和global的用法
查看>>
Ubuntu 12.04 修改/etc/resolv.conf重启后还原成修改前状态解决办法
查看>>
Python—redis
查看>>