hdoj1698【线段树Lazy操作】
区间更新lazy操作一发。
#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
/*
DOTA中屠夫的钩子有N个链子组成,每个链子可有金,银,铜,三种材质做成,
铜链价值1,银价值2,金价值3,
先对钩子进行Q次的更新操作,
求出更新完后钩子的价值。
*/
const int N=100007;
struct st{
int left,right;
int sum;
int val;
};
st q[N*4];
int n,m;
void build(int num,int L,int R)
{
q[num].left=L;
q[num].right=R;
if(L==R)
{
q[num].sum=1;
q[num].val=0;
return;
}
build(2*num,L,(L+R)/2);
build(2*num+1,(L+R)/2+1,R);
q[num].sum=q[2*num].sum+q[2*num+1].sum;
q[num].val=0;
}
void update(int num,int s,int t,int c)
{
if(q[num].left>=s&&q[num].right<=t)
{
q[num].val=c;
q[num].sum=c*(q[num].right-q[num].left+1);
return;
}
if(q[num].val)
{
q[2*num].val=q[num].val;
q[2*num].sum=q[num].val*(q[2*num].right-q[2*num].left+1);
q[2*num+1].val=q[num].val;
q[2*num+1].sum=q[num].val*(q[2*num+1].right-q[2*num+1].left+1);
q[num].val=0;
}
int mid=(q[num].left+q[num].right)/2;
if(mid>=t)
update(2*num,s,t,c);
else if(mid<s)
update(2*num+1,s,t,c);
else
{
update(2*num,s,mid,c);
update(2*num+1,mid+1,t,c);
}
q[num].sum=q[2*num+1].sum+q[2*num].sum;
}
int main()
{
int t;
scanf("%d",&t);
int cas=1;
while(t--)
{
scanf("%d",&n);
build(1,1,n);
scanf("%d",&m);
while(m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(1,a,b,c);
}
printf("Case %d: The total value of the hook is %d.\n",cas++,q[1].sum);
}
return 0;
}
hdoj1698【线段树Lazy操作】的更多相关文章
- HDU 3954 Level up(多颗线段树+lazy操作)
又是一开始觉得的水题,结果GG了好久的东西... 题意是给你n个英雄,每个英雄开始为1级经验为0,最多可以升到k级并且经验一直叠加,每一级都有一个经验值上限,达到就升级.接着给你两种操作:W li r ...
- poj 3237 树链剖分模板(用到线段树lazy操作)
/* 本体在spoj375的基础上加了一些操作,用到线段树的lazy操作模板类型 */ #include<stdio.h> #include<string.h> #includ ...
- POJ3468【线段树lazy操作】
上午理论AC,打到现在快吐了... 一个那么**Lazy操作打成这样,query操作和update操作都有问题,妈蛋,发现是mid<=s+1-真是蠢到家,明明是mid+1<=s卧槽连左和右 ...
- 分块+lazy 或者 线段树+lazy Codeforces Round #254 (Div. 2) E
E. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 线段树+lazy标记 2019年8月10日计蒜客联盟周赛 C.小A的题
题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r] ...
- POJ 2777——线段树Lazy的重要性
POJ 2777 Count Color --线段树Lazy的重要性 原题 链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000 ...
- JuQueen(线段树 lazy)
JuQueen Time Limit: 5 Sec Memory Limit: 512 MB Description Input Output Sample Input 10 10 5 state ...
- hdu 2871 线段树(各种操作)
Memory Control Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 数据结构--线段树--lazy延迟操作
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53749 ...
随机推荐
- call lua function from c and called back to c
Just a simple example: --The c file: #include <stdio.h> #include "lua.h" #include & ...
- [Testing] Config jest to test Javascript Application -- Part 2
Setup an afterEach Test Hook for all tests with Jest setupTestFrameworkScriptFile With our current t ...
- BeagleBone Black Industrial 工业版介绍
前言 在电子发烧友论坛看到有Beaglebone Black Industrial版的试用,这里介绍一下这块开发板. BBB是开源硬件,原理图.BOM等都开放下载,所以也有诸多兼容板. BBB兼容产品 ...
- UI标签库专题二:JEECG智能开发平台Column(列) 子标签
UI标签库专题二:JEECG智能开发平台Column(列) 子标签 1.1. Column(列) 子标签 1.1.1. 演示样例 <t:dgCol title="年龄" ...
- Andrew Ng的机器学习视频文件夹(from coursera, 2014)
第一周: 简单介绍机器学习,有监督学习.无监督学习. 1-1,1-2,1-3,1-4 第二周: 2-1:回归问题举例 2-2:介绍cost function定义. 2-3:在回归函数是一个经过原点的直 ...
- HTML制作练习
- 【转载】C#之C#、.NET Framework、CLR的关系
C#..NET Framework.CLR的关系 很多人没有将C#..NET Framework(.NET框架).CLR(Common Language Runtime,公共语言运行库)这三者之间的关 ...
- HDU 5274 Dylans loves tree(LCA+dfs时间戳+成段更新 OR 树链剖分+单点更新)
Problem Description Dylans is given a tree with N nodes. All nodes have a value A[i].Nodes on tree i ...
- python处理blog文件数据
以下是Python数据处理的题目说明与要求: The attachment is a log file used to show running status of set-top-box, and ...
- Apache Qpid CPP的编译与安装
单机Broker部署(windows/linux) 在Windows/Linux上部署QPID Broker的方法. Windows 需要预先准备的文件和程序 qpid-cpp-0.32.tar.gz ...