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 ...
随机推荐
- IOS学习2
1. #import,#include 和@class的区别 都引用一个类,根本定义区别:#include ,#import会把所有的copy一份到该文件 #import比#include的优势,im ...
- SQL Server 基础:拾遗
1.一条完整的sql语句: select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 having 筛选条件 ...
- 网页绘制图表 Google Charts with JavaScript #2 ....与ASP.NET网页结合 (ClientScriptManager.RegisterStartupScript 方法)
此为文章备份,原文出处(我的网站) 网页绘制图表 Google Charts with JavaScript #2 ....与ASP.NET网页结合 (ClientScriptManager.Regi ...
- STL之容器基本操作
容器类 STL Container Header Applications vector <vector> 直接访问任意元素,快速插入.删除尾部元素 deque <deque> ...
- Spring组件扫描<context:component-scan/>使用详解
1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入. <!-- 注解注入 --> <co ...
- oracle 修改表空间存储路径
[root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 Oracle Database 11g Enterpris ...
- Oracle ClusterwarePRCT-1011 : Failed to run "oifcfg".&nb
OS: Oracle Linux Server release 6.3 DB: Oracle 11.2.0.3 在oracle-linux6.3安装11g RAC,在安装软件时候提示: An inte ...
- Oracle HS (Heterogeneous Services)深入解析 及协同Gateway工作流程(转)
异构的数据源同Oracle Database做交互原理. 图1 上图是一张Oracle 异构连接处理的架构图,其中我们可以看到主要的非数据源模块包括有HS(Heterogeneous Service) ...
- hdu 1277 全文检索
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1277 全文检索 Description 我们大家经常用google检索信息,但是检索信息的程序是很困难 ...
- ios 中怎么自定义(RGB)背景色
1.定义RGB 色彩.随机颜色 我的抽为宏定义.便于各个文件中使用 // 1.获得RGB颜色 #define MTColor(r, g, b) [UIColor colorWithRed:(r)/25 ...