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是区间内连续 ...
随机推荐
- iOS学习之Table View的简单使用
Table View简单描述: 在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View ...
- PHP的数据类型、常量、时间
[数据类型之间相互转换] ◆ 一种是强制转换: setType( 变量, 类型); // 类型 int, integer, float, double,real, bool, boolena, st ...
- 限制Input输入类型的常见代码集合
搜集整理常见的限制INPUT输入类型的实现方式: 1.只能输入和粘贴汉字 <input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g ...
- c#之xml
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- LA 3704 Cellular Automaton
题意概述: 等价地,本题可以转化为下面的问题: 考虑$n \times n$的$0-1$矩阵$A$,在第$i$行上第$[-d+i, d+i]$(模$n$意义下)列对应的元素为$1$,其余为$0$.求$ ...
- Python学习笔记-Day2-Python基础之字典操作
字典的常用操作包括但不限于以下操作: 字典的字典的索引,新增,删除,循环,长度等等 这里将对列表的内置操作方法进行总结归纳,重点是以示例的方式进行展示. 使用type获取创建对象的类 type(dic ...
- 我所了解的cgi(转)
2014-08-25 09:01 by 掸尘, 4410 阅读, 6 评论, 收藏, 编辑 当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服 ...
- android 入门 004 (同一个方法,点击实现不同的效果)
同一个方法,点击实现不同的效果 <Button android:id="@+id/btn3" android:layout_width="wrap_content& ...
- flume ng之TailSource
在它里面自带了一个TailSource以及TailDirSource,这个Source是负责读取一个文件,并一行一行的发送到sink端,而在flume-ng 1.4.0里面没有自带TailSource ...
- mfc截图
1.进入截图状态 PRTSCRING = TRUE;//开始截图标志为TRUE AfxGetMainWnd()->ShowWindow(SW_SHOWMAXIMIZED);//主窗口最大化 Se ...