【HDU1698】【模板】Just a Hook
来源:互联网 发布:网络推广文案案例 编辑:程序博客网 时间:2024/06/06 03:57
线段树
区间修改区间查询
练习的模板题吧
神奇的Pushdown
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define getmid int m=(l+r)>>1const int maxn=111111;int h,w,n;int col[maxn<<2];int sum[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<<1|1]=col[rt]; sum[rt<<1]=(m-(m>>1))*col[rt]; sum[rt<<1|1]=(m>>1)*col[rt]; col[rt]=0; }}void Build(int l,int r,int rt){ col[rt]=0; sum[rt]=1; if(l==r) return; getmid; Build(lson); Build(rson); Pushup(rt);}void Update(int L,int R,int c,int l,int r,int rt){ if(L<=l&&R>=r) { col[rt]=c; sum[rt]=c*(r-l+1); return; } Pushdown(rt,r-l+1); getmid; if(L<=m) Update(L,R,c,lson); if(R>m) Update(L,R,c,rson); Pushup(rt);}int main(){ int a,b,c; int T,n,m; scanf("%d",&T); for(int cas=1;cas<=T;cas++) { scanf("%d%d",&n,&m); Build(1,n,1); while(m--) { scanf("%d%d%d",&a,&b,&c); Update(a,b,c,1,n,1); } printf("Case %d: The total value of the hook is %d.\n",cas,sum[1]); } return 0;}
阅读全文
0 0
- 【HDU1698】【模板】Just a Hook
- hdu1698 Just a Hook
- hdu1698 Just a Hook
- [HDU1698]Just a Hook
- hdu1698 Just a Hook
- hdu1698 Just a Hook
- HDU1698 Just a Hook
- hdu1698 Just a Hook
- HDU1698 Just a Hook
- hdu1698-Just a Hook
- hdu1698 Just a Hook
- Just a Hook hdu1698
- hdu1698 Just a Hook
- hdu1698 Just a Hook
- HDU1698 Just a Hook
- HDU1698 Just a Hook
- HDU1698 Just a Hook
- HDU1698-Just a Hook
- 类加载器(classLoader)
- 20170529
- java面试小结
- 当json中的key值为数字时,怎么用GSON解析?
- 浅谈javascirt this机制
- 【HDU1698】【模板】Just a Hook
- python多版本时候pip安装时候要添加目录
- ZJCOJ: L先生与质数V4(数论)
- tomcat搭建https服务器+阿里云免费证书
- 链表
- map 数组里放 pair 或 结构体
- 找到一本不错的Linux电子书,附《Linux就该这么学》章节目录。
- 用 travis-ci 自动部署 github 上的 angular2 项目到 centos7 的 vps
- hibernate-组件映射-9