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 ...
随机推荐
- angular2 官方demo heroApp
最近学习angular2,于是从官网的hero例子开始学习.经过几番周折终于完成了这个例子.收益匪浅.个人建议在开始学习例子前可以先了解一些概念,模块,组件,装饰器.....,有助于写代码时候的逻辑. ...
- 操作系统:ucore的部分Bug&挑战练习
ucore是清华大学提供的一个学习操作系统的平台.ucore有完整的mooc视频与说明文档. https://objectkuan.gitbooks.io/ucore-docs/content/# 本 ...
- unity3d 初学者遇到的坑(提醒自己不要范同样的错误)
使用NGUI的过程中,总是会发生一些就像我这样的初学者遇到的坑:一直以为在创建 一直以为图中的文字Depth深度大于beijingheitu的深度,会显示在beijingheitu下所有子物体之上, ...
- 201521123105 第8周Java学习总结
1.本周学习总结 1.1思维导图 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 1.删除元素的时候从最后一个元素开始,避免删除元素后位置发生变化而导致 ...
- 201521123028 《Java程序设计》第8周学习总结
1. 本周学习总结 2. 书面作业 Q1.List中指定元素的删除(题目4-1) 1.1 实验总结 Ans: 在这一题中我们需要写两个函数,分别是remove()和convertStringToLis ...
- 201521145048《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- Java十二周总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 书面作业 将Student对象(属性:int id, String name,int age,doubl ...
- 201521123052 《Java程序设计》 第13周学习总结
1. 本周学习总结 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu.edu.cn,分析返回结果有何不同?为什么会有这样的不同? 返回的IP地 ...
- 201521123087《Java程序设计》第10周学习总结
1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 finally题目4-21.1 截图你的提交结果(出现学号)1.2 4-2中finally中捕获异常需要注意什么? 用异常改进Arr ...
- Optional变量初学者指南
苹果三周前发布了Swift. 从那时起,我一直在阅读Swift的官方指南,并在Xcode 6测试版中使用. 我开始喜欢Swift的简单和语法. 与我的团队一起,我仍然在研究新的语言,并看看它与Obje ...