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 为多少 成段更新(通常这对初学者来说是一道坎),需要用到延迟标记(或者说懒惰标记),简单来说就是每次更新的时候不要更新到底,用延迟标记使得更 ...
随机推荐
- Java_myBatis_全局配置文件
mybatis主要需要配置的项: 1.properties 配置文件的“环境变量”键值对 2.typeAliases 输入输出数据的类型 3.mappers 映射配置文件 下面看看实例: < ...
- Cloud9 开发环境部署
安装和部署 cloud9 云端开发环境 简介 Cloud9 是亚马逊发布的一款基于云端的开发环境. AWS Cloud9 是一种基于云的集成开发环境 (IDE),您只需要一个浏览器,即可编写.运行和调 ...
- Docker部署Consul集群
服务介绍 Consul是一种分布式.高可用.支持水平扩展的服务注册与发现工具.包含的特性有:服务发现.健康检查.键值存储.多数据中心和服务管理页面等. 官方架构设计图: 图中包含两个Consul数据中 ...
- jmeter使用正则表达式匹配多个中的响应结果
一.背景: 同一个正则表达式匹配多个响应结果值,之前都是添加多个正则表达式,一个一个去获取需要的值,比较麻烦:今天尝试了一下用一个正则表达式获取响应中所有需要的值,使用这种方式也能够获取多个结果中指定 ...
- ext中grid根据数据不同显示不同样式
核心代码: var clsRender = function(value){ if (value == 'male') { return "<span style='color:red ...
- Linux - sort 排序
-t # 指定排序时所用的栏位分隔字符 -n # 依照数值的大小排序 -r # 以相反的顺序来排序 -f # 排序时,将小写字母视为大写字母 -d # 排序时,处理英文字母.数字及空格字符外,忽略其他 ...
- Cpp读文件、CString转String、String转CString
场景 C++读取文件 技术点 读取文件 fstream提供了三个类,用来实现c++对文件的操作.(文件的创建.读.写). ifstream -- 从已有的文件读入 ofstream -- 向文件写内容 ...
- Protobuf使用手册
Protobuf使用手册 第1章 定义.proto 文件 首先我们需要编写一个 proto 文件,定义我们程序中需要处理的结构化数据,在 protobuf 的术语中,结构化数据被称为 Message. ...
- ubuntu 安装lightgbm
前提:安装好git.cmake 1. 安装lightgbm git clone --recursive https://github.com/Microsoft/LightGBM 2. 编译 下载好的 ...
- TCP建立流程 【转】
解决TCP连接数过多的问题 TCP状态迁移,CLOSE_WAIT & FIN_WAIT2 的问题 TCP状态迁移 大家对netstat -a命令很熟悉,但是,你有没有注意到STATE一栏呢,基 ...