hdu1698线段树的区间更新区间查询
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13001 Accepted Submission(s): 6476
Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y,
For each cupreous stick, the value is 1. For each silver stick, the value is 2. For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations. You may consider the original hook is made up of cupreous sticks.
线段树的区间更新区间查询:
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long int
ll a[];
ll d[];
void build(int b,int c,int x)
{
if(b==c)
{
a[x]=;
return ;
}
int m=(b+c)>>;
build(b,m,x<<);
build(m+,c,x<<|);
a[x]=a[x<<]+a[x<<|];
}
void fun(int x,int m)
{
if(d[x])
{
d[x<<]=d[x<<|]=d[x];
a[x<<]=(m-(m>>))*d[x];
a[x<<|]=(m>>)*d[x];
d[x]=;
}
}
void update(int x,int y,int b,int c,int t,int z)
{
if(x<=b&&y>=c)
{
d[t]=z;
a[t]=(c-b+)*z;
return;
}
fun(t,c-b+);
int m=(b+c)>>;
if(x<=m) update(x,y,b,m,t<<,z);
if(y>m) update(x,y,m+,c,t<<|,z);
a[t]=a[t<<]+a[t<<|];
}
int main()
{
//freopen("int.txt","r",stdin);
int m;
int i,j,x,y,z;
cin>>m;
for(i=;i<=m;i++)
{
int n,k;
memset(a,,sizeof(a));
memset(d,,sizeof(d));
cin>>n>>k;
build(,n,);
for(j=;j<k;j++)
{
scanf("%d%d%d",&x,&y,&z);
update(x,y,,n,,z);
}
cout<<"Case "<<i<<": The total value of the hook is "<<a[]<<"."<<endl;
}
}
hdu1698线段树的区间更新区间查询的更多相关文章
- HDU1698 线段树(区间更新区间查询)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1698:Just a Hook(线段树,区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- UVA 12436-Rip Van Winkle's Code(线段树的区间更新)
题意: long long data[250001]; void A( int st, int nd ) { for( int i = st; i \le nd; i++ ) data[i] = da ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- zoj3686(线段树的区间更新)
对线段树的区间更新有了初步的了解... A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a ...
- Color the ball (线段树的区间更新问题)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
Color the Ball Time Limit: 2 Seconds Memory Limit: 65536 KB There are infinite balls in a line ...
随机推荐
- 模仿Spring实现注解注入
写这个极其蛋疼,我一直在想我们用SSM写项目时,写Service和Controller的时候,会给Service和Controller私有属性,比如Service需要dao,Controller需要S ...
- java IO输入输出流实现文本复制
- pythonl练习
练习:用户输入姓名.年龄.工作.爱好 ,然后打印成以下格式 ------------ info of Egon ----------- Name : Egon Age : 22 Sex : male ...
- python中字符串中一些函数的用法
1..capitalize():字符串的首字母大写: 2..count():字符串中的某个字母的个数: 3..center(50,'-'):对象居中,且左右用'-'补齐: 4..encode():吧字 ...
- oracle得到日期对应的星期
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp56 select to_char(sysdate,'ww') fro ...
- FPGA学习:VHDL设计灵活性&不同设计思路比较
概要 由于VHDL编程实现数字电路具有很高的灵活性,为多种不同的思路编写实现同一种功能提供了可能.这些不同的设计思路,在耗费资源,可靠性,速度上也有很大的差异,往往需要我们根据实际需求和资源条件选择适 ...
- 201521123022 《Java程序设计》 第六周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 Q1.clone方法 Q1.1 Objec ...
- 201521123031《Java程序设计》 第2周学习总结
1. 本周学习总结 (1)能够更加熟练地使用码云 (2)学习了Arrys和String的用法和一些运用 (3)懂得如何查询函数的源代码,通过查看源代码,能够更深入的了解函数适用情况以及利弊 2. 书面 ...
- 12个Sublime Text应用技巧和诀窍
本文为您提供Sublime Text编辑器的12个技巧和诀窍,深入挖掘这个看似简洁的代码编辑器,背后所隐藏的实现各种高级功能的无限可能. 1) 选择 以下是一些Sublime Text选择文本的快捷键 ...
- 201521123072《java程序设计》第十四周学习总结
201521123072<java程序设计>第十四周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库 ...