题目链接: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. UIControl-IOS发展

    UIKit提供了一组控件:UISwitch开关.UIButtonbutton.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件. UIPageCo ...

  2. schedule vs scheduleAtFixedRate

    最好的方法是在两者之间区分 timer灵感时间设定过去时间T,scheduleAtFixedRate将从T现在所有的任务中运行,schedule而该任务将只运行从现在开始计时. public clas ...

  3. 集差集 哈希表 比较数据库的照片和server画面上,将server垃圾上的图片删除

    SSH 骨架code: public String deleRubbishAd(){ int deleADcount = 0; rubbishADtp = configDao.rubbishADtp( ...

  4. Android - 和其他APP交互 - 把用户带到其他app

    Android的重要功能之一就是app可以根据要执行的操作让用户启动另外一个app.例如,app有一个商业地址然后想要在地图上显示,并不需要在app中加一个显示地图的activity,可以直接用Int ...

  5. POJ 1176 Party Lamps (DFS)

    对于一束灯光.提供四种改变彩灯状态(ON<=>OFF)的操作:a.改变全部彩灯状态:b.改变奇数彩灯状态.c.改变偶数彩灯状态:d.改变3k+1号彩灯状态(1,4,7,10...). 给定 ...

  6. ASP.NET自定义控件组件开发 第一章 第二篇 接着待续

    原文:ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 ASP.NET自定义控件组件开发 第一章 第二篇 接着待续 很感谢大家给我的第一篇ASP.NET控件开发的支持!在写这些之前,我也看了 ...

  7. MSXML2;System.ServiceModel.Configuration;对应dll的添加方法

  8. IDF - CTF - 牛刀小试

    找学校CTF好地方,IDF实验室CTF训练营(http://ctf.idf.cn/). . 刚接触CTF.来玩下牛刀小试.AK了. . 好爽好爽.. 1.摩斯password 嘀嗒嘀嗒嘀嗒嘀嗒 时针它 ...

  9. Java String 类的 equals 和 ==

    public class Test_String { public static void main(String[] args) { String a = new String("aa&q ...

  10. [Cocos2d-x]在Cocos2d-x 3.x如何通过版本号WebSocket连接server数据的传输

    WebSocket 首先新建一个空的目录,通过npm安装nodejs-websocket: npm install nodejs-websocket 新建app.js文件: var ws = requ ...