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 ...
随机推荐
- 获取月份对应的day
function getDaysInMonth(month, year) { , , , , , , , , , , , ]; //主要处理二月份的天数 ) && (year % == ...
- Java 第三天 Gradle和其它
Gradle 是以 Groovy 语言为基础,面向Java应用为主.基于DSL(领域特定语言)语法的自动化构建工具. 下载地址 http://www.gradle.org/downloads 环境变量 ...
- Learning Scrapy笔记(一)- Scrapy简单介绍
Scrapy简述 Scrapy十一个健壮的,用来从互联网上抓取数据的web框架,Scrapy只需要一个配置文件就能组合各种组件和配置选项,并且Scrapy是基于事件(event-based)的架构,使 ...
- 09-排序3 Insertion or Heap Sort
和前一题差不多,把归并排序换成了堆排序.要点还是每一次排序进行判断 开始犯了个错误 堆排序该用origin2 结果一直在排序origin ,误导了半天以为是逻辑错误...一直在检查逻辑 建立最大堆 排 ...
- STM32F0xx_DMA收发USART数据配置详细过程
前言 关于DMA(Direct Memory Access)的功能,前面关注我微信的人应该知道,其实我已经在F1芯片上简单讲了一下.有网友要求在F0讲解一下使用DMA收发串口数据.今天就应网友要求总结 ...
- linux MTD系统解析(转)
MTD,Memory Technology Device即内存技术设备,在Linux内核中,引入MTD层为NOR FLASH和NAND FLASH设备提供统一接口.MTD将文件系统与底层FLASH存储 ...
- 同花顺面试经验(搜索引擎C++后台研发)
1.为什么要网页查重 ,怎么查重 2.软 硬cache是指什么 3.多线程编程:互斥变量 和 条件变量 函数怎么写 4.网络编程: epoll干什么的,有什么功能 5.网络编程:select 和 ep ...
- 欢迎来到vmax-tam的博客
欢迎来到vmax-tam的博客 我是一个新手程序员 以后会不断学习 把学到的东西记录下来 和大家一起分享的 谢谢大家指教
- sftp
SFTP 为 SSH的一部分,是一种传输档案至 Blogger 伺服器的安全方式.其实在SSH软件包中,已经包含了一个叫作SFTP(Secure File Transfer Protocol)的安全文 ...
- Lex+YACC详解
1. 简介 只要你在Unix环境中写过程序,你必定会邂逅神秘的Lex&YACC,就如GNU/Linux用户所熟知的Flex&Bison,这里的Flex就是由Vern Paxon实现的一 ...