成段更新

这是一种把 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. log4j里面的info,debug,error级别有什么区别

    一共分为五个级别:DEBUG.INFO.WARN.ERROR和FATAL.这五个级别是有顺序的,DEBUG < INFO < WARN < ERROR < FATAL,明白这一 ...

  2. IOS5基础教程之一-----如何创建XCode项目

    一.IOS的基础知识 1.只有一个应用程序正在运行.在IOS上,每一段时间内只能激活一个应用程序并在屏幕上显示. 2.只有一个窗口.只允许应用程序操作的一个窗口. 3.访问受限.只能在IOS为应用程序 ...

  3. hdwiki中model模块的应用

    control中调用model原则是这样的,如果你的这个model在本control中大部分方法中都要用到,那么,就写在构造函数里面.例如,名字为doc的control的构造函数如下: functio ...

  4. java 打印出99乘法口诀表

    public class Mutiplay { /** *实现99乘法表 * @param args */ public static void main(String[] args) { Syste ...

  5. 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...

  6. Case of the Zeros and Ones 分类: CF 2015-07-24 11:05 15人阅读 评论(0) 收藏

    A. Case of the Zeros and Ones time limit per test 1 second memory limit per test 256 megabytes input ...

  7. 解决maven项目将model version改成3.0版本问题

    找到项目目录,找到.setting文件 找到org.eclipse.wst.common.project.facet.core.xml文件 修改如下标签 <installed facet=&qu ...

  8. Struts2的处理结果(三)——动态配置结果

    Struts2的处理结果(三) --动态配置结果 1.使用表达式语法 示例: <struts> <constant name="struts.enable.DynamicM ...

  9. Web自定义协议,BS端启动CS端,

    实例 1.准备CS项目,windows窗体应用程序,拖进来一个label控件来接受BS的参数,并显示,右击生成,复制该文件的bin目录下的exe,例如放在以下路径,例如C:\\simu\\下, 2.编 ...

  10. 【leetcode❤python】 Maximum Depth of Binary Tree

    #-*- coding: UTF-8 -*- # Definition for a binary tree node.# class TreeNode(object):#     def __init ...