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是区间内连续 ...
随机推荐
- vs2010 仿XCode风格的头注释宏
Sub DocumentFileHeader() Dim star As String star = "//***************************************** ...
- Facebook MyRocks at MariaDB
Recently my colleague Rasmus Johansson announced that MariaDB is adding support for the Facebook MyR ...
- AngularJS 实现的输入自动完成补充功能
1.首先需要引入:angucomplete.js第三方库 2.增加model : var app = angular.module('app', ["angucomplete"]) ...
- FZU 2105 Digits Count(线段树)
Problem 2105 Digits Count Accept: 302 Submit: 1477 Time Limit: 10000 mSec Memory Limit : 262144 KB P ...
- 基于clahe的图像去雾
基于clahe的图像去雾 通过阅读一些资料,我了解到clahe算法对图像去雾有所价值,正好opencv中有了实现,拿过来看一看. 但是现在实现的效果还是有所差异 #); clahe] ...
- 【TCP】超时与重传
在TCP连接中假设发送方一开始便向网络发送多个报文段,直到达到接收方通告的窗口大小为止.当发送方和接收方处于同一个区域网段时,这种方式是可以的.但是如果发送方和接收方之间存在多个路由器和速率较慢的链路 ...
- asp.net webapi初探(一)
本人对webapi尚没有深入研究,初次接触发现了在数据请求时的几点现象. 先切入代码 1.如果action中开头带有Get默认就是get方式,不带Get默认就是post方式 public string ...
- HDU 4630 No Pain No Game 线段树 和 hdu3333有共同点
No Pain No Game Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 公共控件Listview
ListView属性中,Items是行的总集合,Items集合中的每一个是一行,Items集合里面有ListViewItem集合,这个集合实例化:ListViewItem li=new ListVie ...
- (转)Linux下安装rar fou linux
在Linux下安装rar fou linux rar for linux 软件下载地址:http://www.rarsoft.com/download.htm 到目前为止最新的版本为4.10 beta ...