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

线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息)

#pragma comment(linker,"/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define N 100010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int sum[N<<],col[N<<];
void Pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void Pushdown(int rt,int len)
{
if(col[rt])
{
col[rt<<]=col[rt<<|]=col[rt];
sum[rt<<]=col[rt]*(len-(len>>));
sum[rt<<|]=col[rt]*(len>>);
col[rt]=;
}
}
void build(int l,int r,int rt)
{
col[rt]=;
if(l==r)
{
sum[rt]=;return;
}
int m=(l+r)>>;
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)
{
sum[rt]=(r-l+)*c;
col[rt]=c;
return;
}
Pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m)update(L,R,c,lson);
if(m<R)update(L,R,c,rson);
Pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
return sum[rt];
}
Pushdown(rt,r-l+);
int m=(l+r)>>;
int res=;
if(L<=m)res+=query(L,R,lson);
if(m<R)res+=query(L,R,rson);
return res;
}
int main()
{
int n,m,t,cas=;
int a,b,c;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
build(,n,);
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,,n,);
}
printf("Case %d: ",cas++);
printf("The total value of the hook is %d.\n",query(,n,,n,));
}
}

hdu1698(线段树)的更多相关文章

  1. hdu1698 线段树区间更新

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

  2. hdu1698线段树区间更新

    题目链接:https://vjudge.net/contest/66989#problem/E 坑爹的线段树照着上一个线段树更新写的,结果发现有一个地方就是不对,找了半天,发现是延迟更新标记加错了!! ...

  3. hdu1698线段树的区间更新区间查询

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

  4. HDU1698 线段树(区间更新区间查询)

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

  5. hdu1698(线段树区间替换模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意: 第一行输入 t 表 t 组测试数据, 对于每组测试数据, 第一行输入一个 n , 表示 ...

  6. hdu1698(线段树的区间替换)

    HDU1698 #include <bits/stdc++.h> using namespace std; #define Maxn 1001000*4 struct Node{ int ...

  7. HDU1698 线段树入门之区间修改/查询(lazy标记法)

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

  8. Just a Hook(HDU1698 线段树的简单应用)

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

  9. HDU1698 线段树(区间更新区间查询)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  10. hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)

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

随机推荐

  1. 基于visual Studio2013解决C语言竞赛题之1083人机博弈

        题目 解决代码及点评 /************************************************************************/ /* ...

  2. struts2 <s:iterator/>怎样取得循环的索引

    <s:iterator value="list" id="user" status="L"> <s:property va ...

  3. python 站点爬虫 下载在线盗墓笔记小说到本地的脚本

    近期闲着没事想看小说,找到一个全是南派三叔的小说的站点,决定都下载下来看看,于是动手,在非常多QQ群里高手的帮助下(本人正則表達式非常烂.程序复杂的正则都是一些高手指导的),花了三四天写了一个脚本 须 ...

  4. 如果一个Object对象可能是集合或者数组那么如何对其进行迭代

    需求:一个方法传入的参数是Object类型(假设对象为“items”,使用Object类型也是为了使用多态而增加方法复用性),但已知这个Object对象可能是集合,包括Collection和Map,也 ...

  5. [置顶] 手把手教你iOS消息推送证书生成以及Push消息

    iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...

  6. 几款屏幕录制软件 ActivePresente

    几款屏幕录制软件,最强大是  ActivePresenter ,免费版, 足以应对我们日常需求.列表如下 支持系统:W-Windows,L-Linux,M-Mac 软件 格式 W L M 免费 说明 ...

  7. Sql Server中COUNT(字段名)跟COUNT(*)的特殊不同点

    今天有个需求,有2张表: 1.一个“搜索记录”表search,一个“搜索后下载记录”表down 2.映射关系:每一个下载记录对应一条搜索记录,                           第个 ...

  8. H-index因素

    Problem Description Paper quality and quantity have long been used to measure a research's scientifi ...

  9. SQL--存储过程+触发器 对比!

    一.存储过程 一:存储过程:存储过程是一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中. 可以用存储过程名字和参数来调用存储过程,这样可以避免代码重复出现,用起来也方便. 例:    下面 ...

  10. sqlserver 存储过程学习笔记(二) 在项目中的应用<多表分页>

    (1)存储过程建立 USE [NewPlat] GO /****** Object:  StoredProcedure [dbo].[usp_PagingLarge]    Script Date: ...