题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698

线段树+lazy操作     线段树是从上到下开始建树,树状数组是从下到上建树....

代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <ctype.h>
#include <iomanip>
#include <queue>
#include <stdlib.h>
using namespace std; #define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1 const int maxn=;
int n;
int s[maxn<<],sum[maxn<<]; void pushup(int rt) //
{
sum[rt] = sum[rt << ] + sum[rt << |];
} void pushdown(int rt,int m) //下标为n,这段区间有m个数
{
if( s[rt] ){
s[ rt<< ]=s[ rt<<| ]=s[ rt ];
sum[ rt<< ]=(m-m/)*s[ rt ];
sum[ rt<<| ]=(m/)*s[ rt ];
s[ rt ]=;
}
} void build( int l,int r,int rt ) //建树
{
sum[ rt ]=;
s[ rt ]=;
if( l==r ){
return ;
}
int mid;
mid=(l+r)>>;
build( lson );
build( rson );
pushup( rt ); } void update(int a,int b,int c,int l,int r,int rt) //更新
{
if(a<=l && b>=r){
s[ rt ]=c;
sum[ rt ]=(r-l+)*c;
return;
}
pushdown( rt,r-l+ );
int mid=(l+r)>>;
if( a<=mid )
update( a,b,c,lson );
if( b>mid )
update( a,b,c,rson );
pushup( rt );
return ;
} int query( int a,int b,int l,int r,int rt) //查询
{
if(a==l && b==r){
return sum[ rt ];
}
int mid=(l+r)>>;
int t1,t2;
if( b<=mid )
return query( a,b,lson );
else if( a>mid )
return query( a,b,rson );
else
return query( a,mid,lson )+query( mid+,b,rson );
} int main()
{
int t;
scanf("%d",&t);
for(int i=;i<=t;i++){
scanf("%d",&n);
build( ,n, );
int m;
scanf("%d",&m);
int a,b,c;
while(m--){
scanf("%d%d%d",&a,&b,&c);
update( a,b,c,,n, );
//for( int j=1;j<=25;j++ )printf("j:%d %d\n",j,sum[j]);
}
printf("Case %d: The total value of the hook is %d.\n",i,sum[ ]/*query( 1,n,1,n,1 )*/ );
}
return ; }

hdu Just a Hook的更多相关文章

  1. hdu just a hook(线段树,区间修改)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

  3. HDU 1698 & UESTC 1228 Just a hook

    算是线段树中的一道水题了,必须用到懒操作,否则会超时.或者也可以刚开始不计算和,只更新节点,最后算整个线段的颜色和. 1.懒操作法 /* 908ms 3448KB in HDU OJ*/ #inclu ...

  4. HDU 1698 Just a Hook (线段树区间更新)

    题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...

  5. hdu 1689 Just a Hook

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 Just a Hook Time Limit: 4000/2000 MS (Java/Others)    ...

  6. HDU 1698 Just a Hook(线段树成段更新)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description   In the game of DotA, P ...

  7. (线段树)Just a Hook -- hdu -- 1689

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 思路: 我的想法很简单,像上一题一样从后面向前面来算,前面已经覆盖的,后面自然不能再来计算了,具体 ...

  8. HDU 1698 just a hook 线段树,区间定值,求和

    Just a Hook Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  9. HDU 1698 Just a Hook(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意:给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和. 思路: 区间更新题目 ...

随机推荐

  1. HTML5实际和离线应用分析

    当前离线Web申请书,即,该装置不能访问因特网时的应用的执行.HTML5离线应用重点,主要开发人员希望.步骤离线应用开发有:首先我们应该知道设备是否可以连接;然后,它也应该可以访问某些资源(像.CSS ...

  2. 白板编程浅谈——Why, What, How(转)

    原文链接:http://lucida.me/blog/whiteboard-coding-demystified/ 这篇文章节选自我正在撰写的一本关于应届生面试求职的书籍,欢迎在评论或微博(@peng ...

  3. JSplitPane demo

    package example; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; imp ...

  4. 【转】Directx11 SDK文档

    原文地址:http://blog.csdn.net/cmt100/article/details/6343274 总结 这是一个初步的教程.我们将通过必要的步骤来创建一个Win32 Applicati ...

  5. Windows8.1和Ubuntu14.04双系统卸载Ubuntu參考教程[图]

    我之前编写并公布了<Windows8.1安装Ubuntu14.04双系统參考教程及双硬盘注意事项>这篇教程,而本文提供的卸载Ubuntu方法适用于这篇教程,其它方法安装的Ubuntu可适当 ...

  6. Atitit.Hibernate于Criteria 使用汇总and 关系查询 and 按照子对象查询 o9o

    Atitit.Hibernate于Criteria 使用总结and 关联查询 and 依照子对象查询 o9o 1. Criteria,,Criterion ,, 1 <2. 基本的对象黑头配置磊 ...

  7. 对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator)

    原文:对比Windows 8模拟器(Simulator)和Windows Phone仿真器(Emulator) 从事移动应用开发,经常会用到模拟器(Simulator)和仿真器(Emulator),本 ...

  8. S2SH新手框架结构的准备工作只需要导入这些文件

    实习北京最近一直在某公司.时间很冲突,总想着有事找东西坐,思想,做事先成套我吧 一套完整的东西想好主题,术去实现了,在学校尽管说是学了J2EE,可是确实没学到东西,Struts2+Hibernate不 ...

  9. shell编程三大神器之grep

  10. Android于JNI调用列出的程序

    1.安装和下载cygwin,下载Android NDK: 2.于ndk工程JNI接口设计: 3.采用C/C++实现本地方法. 4.JNI生成动态链接库.so档: 5.动态链接库副本javaprojec ...