成段更新

这是一种把 num[]上空结点当做lazy标志使用的方法

都一样。。。

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
const int MM=;
int num[MM<<];
int flag;
void down(int k)
{
num[k<<]=num[k<<|]=num[k];
num[k]=;
}
void buildtree(int l,int r,int id)
{
num[id]=flag;
if(l==r)
{
return;
}
else
{
int mid=(l+r)>>;
buildtree(l,mid,id<<);
buildtree(mid+,r,id<<|);
}
}
int query(int l,int r,int id)
{
if(num[id])
{
return (r-l+)*num[id]; }int mid=(l+r)>>,t1,t2;
t1=query(lson);
t2=query(rson);
return t1+t2;
}
void update(int L,int R,int l,int r,int id)
{
if(L<=l&&r<=R)
{
num[id]=flag;return;
}
if(num[id])down(id);
int mid=(l+r)>>;
if(L<=mid)update(L,R,lson);
if(R>mid)update(L,R,rson);
}
int main()
{
int t,n,m,cas,i,x,y,ans;
scanf("%d",&t);
for(cas=;cas<=t;cas++)
{
scanf("%d %d",&n,&m);
flag=;
buildtree(,n,);
while(m--)
{
scanf("%d %d %d",&x,&y,&flag);
update(x,y,,n,);
}
ans=query(,n,);
printf("Case %d: The total value of the hook is %d.\n",cas,ans );
}
return ;
}

HDU 1698的更多相关文章

  1. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  2. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

  3. hdu 1698 线段树 区间更新 区间求和

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

  4. HDU - 1698 线段树区间修改,区间查询

    这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...

  5. Hdu 1698(线段树 区间修改 区间查询)

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

  6. HDU(1698),线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...

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

    有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...

  8. hdu 1698 线段树 区间修改

    #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...

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

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

  10. HDU 3911 线段树区间合并、异或取反操作

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...

随机推荐

  1. 【jqGrid for ASP.NET MVC Documentation】.学习笔记.7.搜索过滤数据

    1 基础 搜索和过滤功能,是使用确定的条件,查找匹配行数据.jqGrid提供几种搜索模式: Search Dialog 单搜索选项 Search Dialog 多搜索选项 ToolBar Search ...

  2. 利用python进行数据分析 (学习笔记)

    第一章:准备工作 1.重要的Python库 (1)NumPy:Python科学计算的基础包.功能有:

  3. HDU 2665 && POJ 2104(主席树)

    http://poj.org/problem?id=2104 对权值进行建树(这个时候树的叶子是数组b的有序数列),然后二分查找原数列中每个数在有序数列中的位置(即第几小),对每一个前缀[1,i]建一 ...

  4. RadioGroup+Fragment 使用Fragment的add()方法,防止使用replace每次都重新加载页面,造成资源浪费

    radiogroup+fragment是很常用的主页导航控件,之前为了代码简便一直使用的replace()替换fragment,代码如下: getSupportFragmentManager().be ...

  5. A类地址

    一个A类IP地址由1字节(每个字节是8位)的网络地址和3个字节主机地址组成,网络地址的最高位必须是“0”.A类IP的地址第一个字段范围是0~127,但是由于全0和全1的地址用作特殊用途,实际可指派的第 ...

  6. poj2482 Stars in Your Window

    此题可用线段树或静态二叉树来做. 考虑用线段树: 很容易想到先限定矩形横轴范围再考虑在此纵轴上矩形内物品总价值的最大值. 那么枚举矩形横轴的复杂度是O(n)的,考虑如何快速获取纵轴上的最大值. 我们不 ...

  7. 山东理工大学第七届ACM校赛-飞花的糖果 分类: 比赛 2015-06-26 10:27 15人阅读 评论(0) 收藏

    飞花的糖果 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 一日,飞花壕大手一挥,买了N个的两两不相同糖果,他想要拿出M个糖果送给他心仪 ...

  8. 如何在linux下查看gpu信息

    ~$ lspci | grep -i vga01:00.0 VGA compatible controller: NVIDIA Corporation GF119 [GeForce GT 610] ( ...

  9. 2015年江西理工大学C语言程序设计竞赛(初级组)

    JankTao相亲记 解法:排序 #include<stdio.h> #include<string.h> #include<iostream> #include& ...

  10. 快速编译system.img、userdata.img、boot.img的方法

    快速编译system.img和boot.img的方法 快速编译system.img,可以使用这个命令: #make systemimage 快速编译boot.img,可以使用以下命令: #make b ...