hdu 1698 线段树 区间修改
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 200010
#define INF 0x7fffffff
#define inf 10000000
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
using namespace std; struct node {
int ri, le, v, sum;
}; node tree[2*maxn]; void build(int id, int L, int R) {
tree[id].le = L, tree[id].ri = R;
if(L == R) {
tree[id].v = 1, tree[id].sum = 1;
}
else {
int M = L + (R-L)/2;
build(id*2, L, M);
build(id*2+1, M+1, R);
tree[id].v = 0;
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
}
} void update(int id, int L, int R, int c) {
if(tree[id].le == L && tree[id].ri == R) {
tree[id].v = c;
tree[id].sum = c*(tree[id].ri-tree[id].le+1);
}
else {
if(tree[id].v > 0) {
tree[id*2+1].v = tree[id*2].v = tree[id].v;
tree[id*2].sum = tree[id].v*(tree[id*2].ri - tree[id*2].le + 1);
tree[id*2+1].sum = tree[id].v*(tree[id*2+1].ri - tree[id*2+1].le + 1);
}
tree[id].v = 0;
int M = tree[id].le + (tree[id].ri - tree[id].le)/2;
if(R <= M) update(id*2, L, R, c);
else if(L > M) update(id*2+1, L, R, c);
else {
update(id*2, L, M, c);
update(id*2+1, M+1, R, c);
}
tree[id].sum = tree[id*2].sum + tree[id*2+1].sum;
}
} int main()
{
int t, n, m, ca = 0;
scanf("%d", &t);
while(t --)
{
scanf("%d%d", &n, &m);
build(1, 1, n);
for(int i = 0; i < m; ++ i)
{
int y11, y22, c;
scanf("%d%d%d", &y11, &y22, &c);
update(1, y11, y22, c);
}
printf("Case %d: The total value of the hook is %d.\n", ++ ca, tree[1].sum);
}
return 0;
}
hdu 1698 线段树 区间修改的更多相关文章
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- 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 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 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 3397 线段树区间修改
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
随机推荐
- spark概论
一.概述 1.轻:(1)采用语言简洁的scala编写:(2)利用了hadoop和mesos的基础设施 2.快:spark的内存计算.数据本地性和传输优化.调度优化,使其在迭代机器学习,ad-hoc ...
- DBGridEh 点击表头排序方法
方法1: (不用编程写代码) 程序中引用 单元 EhLibCDS设置DBGridEh的属性: ColumnDefValues.Title.TitleButton = True Op ...
- C#之匿名类型与隐式局部变量
一.匿名类型 下面一段代码展示了如何定义并且使用匿名类型: static void Main(string[] args) { var patent1 = new { Title = "Ne ...
- 共享内存shared pool (4):Library cache 转储文件
上一篇blog只是从概念上理解Library cache,本篇则是将Library cache从内存中dump出来,看看其结构. 基本命令 ALTER SESSION SET EVENTS 'imme ...
- python 校招信息爬虫程序
发现一个爬虫程序,正在学习中: https://github.com/lizherui/spider_python
- Android JNI如何调用第三方库
http://www.2cto.com/kf/201504/388764.html Android JNI找不到第三方库的解决方案 cannot load library 最近做一个jni项目,拿到的 ...
- golang的并发
Golang的并发涉及二个概念: goroutine channel goroutine由关键字go创建. channel由关键字chan定义 channel的理解稍难点, 最简单地, 你把它当成Un ...
- SQL Server 批量插入数据的两种方法
在SQL Server 中插入一条数据使用Insert语句,但是如果想要批量插入一堆数据的话,循环使用Insert不仅效率低,而且会导致SQL一系统性能问题.下面介绍 SQL Server支持的两种批 ...
- C# Hadoop学习笔记
记录一下学习地址 http://www.360doc.com/content/14/0607/22/3218170_384675141.shtml
- php之常用函数库
1.时间和日期 如何获取时间戳 time()--从1970年开始计算的毫秒数 echo time(); 日期 echo date('Y-m-d H:i:s'); 获取默认是时区 echo date_d ...