hdu1698
/*
区间更新
*/
#include <cstdio>
#include <algorithm>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = ;
int h , w , n;
int col[maxn<<];
int sum[maxn<<];
void PushUp(int rt) {
sum[rt] = sum[rt<<] + sum[rt<<|];
}
void PushDown(int rt,int m) {
if (col[rt]) {
col[rt<<] = col[rt<<|] = col[rt];
sum[rt<<] = (m - (m >> )) * col[rt];
sum[rt<<|] = (m >> ) * col[rt];
col[rt] = ;
}
}
void build(int l,int r,int rt) {
col[rt] = ;
sum[rt] = ;
if (l == r) return ;
int m = (l + r) >> ;
build(lson);
build(rson);
PushUp(rt);
}
void update(int L,int R,int c,int l,int r,int rt) {
if (L <= l && r <= R) {
col[rt] = c;
sum[rt] = c * (r - l + );
return ;
}
PushDown(rt , r - l + );
int m = (l + r) >> ;
if (L <= m) update(L , R , c , lson);
if (R > m) update(L , R , c , rson);
PushUp(rt);
}
int main() {
int T , n , m;
scanf("%d",&T);
for (int cas = ; cas <= T ; cas ++) {
scanf("%d%d",&n,&m);
build( , n , )
while (m --) {
int a , b , c;
scanf("%d%d%d",&a,&b,&c);
update(a , b , c , , n , );
}
printf("Case %d: The total value of the hook is %d.\n",cas , sum[]);
}
return ;
}
hdu1698的更多相关文章
- hdu1698(线段树的区间替换)
HDU1698 #include <bits/stdc++.h> using namespace std; #define Maxn 1001000*4 struct Node{ int ...
- hdu1698 线段树区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 线段树---成段更新hdu1698 Just a Hook
hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...
- HDU1698 Just a Hook —— 线段树 区间染色
题目链接:https://vjudge.net/problem/HDU-1698 In the game of DotA, Pudge’s meat hook is actually the most ...
- Just a Hook(HDU1698 线段树的简单应用)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- HDU-1698 JUST A HOOK 线段树
最近刚学线段树,做了些经典题目来练手 Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- HDU1698 Just a Hook
Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...
- hdu-------(1698)Just a Hook(线段树区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU1698 Just a Hook (区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【线段树成段更新-模板】【HDU1698】Just a Hook
题意 Q个操作,将l,r 的值改为w 问最后1,n的sum 为多少 成段更新(通常这对初学者来说是一道坎),需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更 ...
随机推荐
- 91 Testing Linux学习笔记
91 Testing Linux学习笔记... 学习地址:91Testing 的Linux教程=====================学习网址:http://www.91testing.net/ar ...
- ansible指路篇-安装及基本命令使用
ansible指路篇-安装及基本命令使用 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是ansible ansible是新出现的自动化运维工具,基于Python开发,集合 ...
- 设计模式---组件协作模式之策略模式(Strategy)
一:概念 Strategy模式,对一系列的算法加以封装,为所有算法定义一个抽象的算法接口,并通过继承该抽象算法接口对所有的算法加以封装和实现,具体的算法选择交由客户端决定(策略). Strategy模 ...
- 线程本地变量ThreadLocal (耗时工具)【原】
线程本地变量类 package king; import java.util.ArrayList; import java.util.List; import java.util.Map; impor ...
- android kotlin Gradle DSL method not found: '1.2.51()'错误,be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
同步的时候遇到这个问题,从log上看是因为gradle的版本不包含kotlin 1.2.51这个method,具体原因我也不是很清楚,大概猜测是kotlin版本的问题,而最新的版本就是1.2.51,所 ...
- android allowbackup
allowbackup 属性是在application 节点下,作用的设置为true,人们可以通过adb 命令备份一份应用的信息,然后在另外一个设备上,还原这份信息,是一种危险操作,所以,我们一般设为 ...
- vue错误记录
启动时报错如下 D:\QQFile\\FileRecv\industry_vue>cnpm run dev > vue_demo@ dev D:\QQFile\\FileRecv\indu ...
- clip:rect()
写进度条的时候用过这个方法,记录一下 它的用法是 .test{ clip: rect(<top>, <right>, <bottom>, <>left) ...
- Vue.js入门系列教程(二)
过滤器:filter 全局过滤器 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 我的Mac中毒了,病毒居然叫做MacPerformance
禁用 ReportCrash 直接干掉进程肯定不管用,从名字就知道这个进程会自动被触发,除非修改系统配置. Google 了一下,发现很简单,在 terminal 里执行 launchctl unlo ...