HDU 1698
成段更新
这是一种把 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的更多相关文章
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU - 1698 线段树区间修改,区间查询
这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...
- Hdu 1698(线段树 区间修改 区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- HDU(1698),线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...
- HDU 1698 (线段树 区间更新) Just a Hook
有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...
- hdu 1698 线段树 区间修改
#include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
- HDU 3911 线段树区间合并、异或取反操作
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...
随机推荐
- ecshop后台增加模板页的方法
CShop的动态模板机制是一个非常灵活的系统,管理员可以在后台根据自己的要求调整模板模块的显示位置.本文详细讲解了如何修改ECSHOP内部结构使得用户可以添加自己的模板页从而方便灵活的使用系统自带的模 ...
- vscode使用php调试
1:首先查看是否安装xdebug扩展 打开终端 ➜ ~ php -vPHP 5.6.24 (cli) (built: Jul 21 2016 14:27:54) Copyright (c) 1997 ...
- js闭包的产生
当函数可以记住并访问所在的词法作用域, 即函数是在当前词法作用域之外执行, 这时就产生了闭包. function a () { function b () { //函数b的词法作用域是在函数a内 ...
- $q服务的API详解
下面我们通过讲解$q的API让你更多的了解promise异步编程模式.$q是做为angularjs的一个服务而存在的,只是对promise异步编程模式的一个简化实现版,源码中剔除注释实现代码也就二百多 ...
- 杭电1012-u Calculate e
#include<stdlib.h>#include <stdio.h> int main () { printf("n e\n"); ...
- jqeury之平移轮播
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- PHP判断键值数组是否存在,使用empty或isset或array_key_exists
<?php $a = array('a'=>1, 'b'=>0, 'c'=>NULL); echo 'a test by empty: ' , empty($a['a']) ...
- poj2429 GCD & LCM Inverse
用miller_rabin 和 pollard_rho对大数因式分解,再用dfs寻找答案即可. http://poj.org/problem?id=2429 #include <cstdio&g ...
- Spring声明式事务管理与配置详解
转载:http://www.cnblogs.com/hellojava/archive/2012/11/21/2780694.html 1.Spring声明式事务配置的五种方式 前段时间对Spring ...
- 如何在linux下查看gpu信息
~$ lspci | grep -i vga01:00.0 VGA compatible controller: NVIDIA Corporation GF119 [GeForce GT 610] ( ...