HDU 1698 Just a Hook(成段更新)
2013-12-07 20:01
351 查看
转载请注明出处:忆梦http://blog.csdn.net/yimeng2013/article/details/17191439
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698线段树功能: update:成端替换
跟着NotOnlySuccess大牛学线段树
#include<cstdio> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #define maxn 111111 int 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 len) { if(col[rt]) { col[rt<<1] = col[rt<<1|1] = col[rt]; sum[rt<<1] = ( len - (len>>1) )* col[rt]; sum[rt<<1|1] = (len >> 1) * col[rt]; col[rt] = 0; } } void build(int l, int r, int rt) { col[rt] = 0; if(l == r) { sum[rt] = 1; return ; } int m = (l + r) >> 1; 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] = (r-l+1) * c; return ; } Pushdown(rt, r-l+1); int m = (l + r) >> 1; if(L <= m) update(L,R, c,lson); if(m < R) update(L, R, c, rson); PushUp(rt); } int main () { int T; scanf("%d", &T); for(int cas = 1; cas <= T; cas++) { int n, m; scanf("%d %d", &n, &m); build(1, n, 1); int a, b, c; 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; }
相关文章推荐
- eclipse for c++程序调试中的问题:cannot open output file study.exe: Permission denied
- 苹果的iOS系统是嵌入式 ?
- Windows Phone 8初学者开发—第16部分:使用应用程序栏
- 站点切换插件使用
- 【HNOI2010 DAY1】合唱队
- 约瑟夫问题(好人坏人)
- 计算机网络中IP地址和MAC地址
- win7下 ,CentOS-6.5-x86_64硬盘安装两个问题
- linux/unix下多进程间的通信
- 目前市场上流行的嵌入式操作系统
- Unix环境高级编程 实例4-7
- webservice服务端和客户端
- 用Java实现约瑟夫环
- Shell脚本的运行
- 第四讲、Java 多媒体编程应用技术
- matlab 与数据库操作
- 在ubuntu下安装ItelliJ
- hdu1007最近点对
- Financial Management
- 如何编程获取Windows NT的性能数据