HDU1698
来源:互联网 发布:mac appstore密码错误 编辑:程序博客网 时间:2024/06/10 12:26
hdu1698
帕吉钩子的每一节有三种材质,每一种的价值不同,问经过数次修改后钩子的总价值。
最基础的线段树区间更新。
做这道题的时候发现左移和右移运算符的优先级要比+和-还要低…
还是太菜
加油!
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;#define MAXN 100010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define mid int m = (l + r) >> 1int sum[MAXN<<2];int 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<<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; sum[rt] = 1; if(l==r) return; mid; 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); mid; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); PushUp(rt);}int query(int L,int R,int l,int r,int rt){ PushDown(rt,r-l+1); int ret = 0; mid; if(L<=m) ret += query(L,R,lson); if(R>m) ret += query(L,R,rson); return ret;}int main(){ ios::sync_with_stdio(false); int T,n,q,a,b,c,casenum; while(cin>>T){ casenum = 0; while(T--){ cin>>n>>q; build(1,n,1); for(int i = 0;i<q;i++){ cin>>a>>b>>c; update(a,b,c,1,n,1); } for(int i = 1;i<=20;i++) cout<<sum[i]<<endl; printf("Case %d: The total value of the hook is %d.",++casenum,sum[1]); } }}
0 0
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- HDU1698
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- hdu1698
- HDU1698
- HDU1698
- hdu1698
- HDU1698
- HDU1698
- Cloudera 从5.2.0升级到最新5.8.2的官方文档翻译
- Android 自定义View之边缘凹凸的优惠券效果
- Jenkins中svn地址有多个,SVN_URL失效的解决办法
- ECMAScript6语法介绍及编程风格
- C语言产生随机数的方法
- HDU1698
- Xcode 8 Convert to Current Swift Syntax Failed
- 复制Java Web项目,Tomcan报上下文错误
- 条件结构
- HibernateValidator的扩展注解类
- leetcode 204. Count Primes
- 提取图像Alpha位图(图片边缘光晕效果)
- 边缘检测
- andriod 开发环境搭建