Can you answer these queries?

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 15314    Accepted Submission(s): 3590

Problem Description
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be marked a value of endurance. For every attack of our secret weapon, it could decrease the endurance of a consecutive part of battleships by make their endurance to the square root of it original value of endurance. During the series of attack of our secret weapon, the commander wants to evaluate the effect of the weapon, so he asks you for help.
You are asked to answer the queries that the sum of the endurance of a consecutive part of the battleship line.

Notice that the square root operation should be rounded down to integer.

 
Input
The input contains several test cases, terminated by EOF.
  For each test case, the first line contains a single integer N, denoting there are N battleships of evil in a line. (1 <= N <= 100000)
  The second line contains N integers Ei, indicating the endurance value of each battleship from the beginning of the line to the end. You can assume that the sum of all endurance value is less than 263.
  The next line contains an integer M, denoting the number of actions and queries. (1 <= M <= 100000)
  For the following M lines, each line contains three integers T, X and Y. The T=0 denoting the action of the secret weapon, which will decrease the endurance value of the battleships between the X-th and Y-th battleship, inclusive. The T=1 denoting the query of the commander which ask for the sum of the endurance value of the battleship between X-th and Y-th, inclusive.
 
Output
For each test case, print the case number at the first line. Then print one line for each query. And remember follow a blank line after each test case.
 
Sample Input
10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
 
Sample Output
Case #1:
19
7
6
 
Source
 题意:
n个数,两种操作:0 b c表示将[b,c]区间的数开方,1 b c表示询问[b,c]区间的和。
代码:
//因为题目中所有和不超过2^63,所以每个数开方次数不超过7,这样在更新[b,c]时
//如果区间内的所有数都是1就不必更新了,否则挨个更新叶子。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn=;
ll sum[maxn*+];
void Pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void Build(int l,int r,int rt)
{
if(l==r){
scanf("%lld",&sum[rt]);
return;
}
int m=(l+r)>>;
Build(l,m,rt<<);
Build(m+,r,rt<<|);
Pushup(rt);
}
void Update(int ql,int qr,int l,int r,int rt)
{
if(l==r){
sum[rt]=sqrt(sum[rt]);
return;
}
if(ql<=l&&qr>=r&&sum[rt]==r-l+) return;
int m=(l+r)>>;
if(ql<=m) Update(ql,qr,l,m,rt<<);
if(qr>m) Update(ql,qr,m+,r,rt<<|);
Pushup(rt);
}
ll Query(int ql,int qr,int l,int r,int rt)
{
if(ql<=l&&qr>=r) return sum[rt];
int m=(l+r)>>;
ll s=;
if(ql<=m) s+=Query(ql,qr,l,m,rt<<);
if(qr>m) s+=Query(ql,qr,m+,r,rt<<|);
return s;
}
int main()
{
int n,m,cas=;
while(scanf("%d",&n)==){
Build(,n,);
scanf("%d",&m);
int a,b,c;
printf("Case #%d:\n",++cas);
while(m--){
scanf("%d%d%d",&a,&b,&c);
int bb=min(b,c),cc=max(b,c);
if(a) printf("%lld\n",Query(bb,cc,,n,));
else Update(bb,cc,,n,);
}
printf("\n");
}
return ;
}

HDU4027 线段树的更多相关文章

  1. hdu-4027线段树练习

    title: hdu-4027线段树练习 date: 2018-10-10 18:07:11 tags: acm 算法 刷题 categories: ACM-线段树 # 概述 这道线段树的题可以说是我 ...

  2. hdu4027线段树

    https://vjudge.net/contest/66989#problem/H 此题真是坑到爆!!说好的四舍五入害我改了一个多小时,不用四舍五入!!有好几个坑点,注意要交换l,r的位置,还有输出 ...

  3. HDU4027(线段树单点更新区间)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  4. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

  5. BZOJ3211花神游历各国-线段树&树状数组-(HDU4027同类型)

    (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 题意:BZOJ HDU  原题目描述在最下面.  两种操作,1:把区间的数字开方一次,2:区间求和. 思路: 线段树:  显然不能暴力 ...

  6. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

  7. hdu4027(线段树)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 线段树功能:区间修改,区间求和. 分析:因为每个数至多开6次平方就变1了,所以对于每一段全为1的 ...

  8. Can you answer these queries?(HDU4027+势能线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...

  9. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

随机推荐

  1. 1.编译azkaban

    1.下载azkaban的源码 https://github.com/azkaban/azkaban.git 然后解压得到azkaban-master.zip,解压:unzip azkaban-mast ...

  2. 《剑指Offer》题十一~题二十

    十一.旋转数组的最小数字 题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组{3, 4, 5, 1, 2}为{ ...

  3. 20172305 2018-2019-1 《Java软件结构与数据结构》第一周学习总结

    20172305 2018-2019-1 <Java软件结构与数据结构>第一周学习总结 教材学习内容总结 本周内容主要为书第一章和第二章的内容: 第一章 软件质量: 正确性(软件达到特定需 ...

  4. 软工1816 · Alpha冲刺(3/10)

    团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 完成了对laravel框架的一整套机制的了解,对后端的处理流程有全面的认识对整 ...

  5. Jedis源码解析——Jedis和BinaryJedis

    1.基本信息 先来看看他们的类定义: public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommands ...

  6. 初学LINUX版本的选择

    1.用于企业环境:建议使用商业版本,例如Red Hat的RHEL或者是Novell的SuSE都是很不错的选择!毕竟企业的环境强调的是永续的经营,你可不希望网管人员走了之后整个机房的主机都没有人管理吧! ...

  7. cacti 添加mysql 监控 (远程服务器)

    监控主机 192.168.24.69 ,以下用A表示 被监控主机 192.168.24.79,以下用B标识   记得在A服务器的cacti中导入监控mysql的templates文件   1.在B上安 ...

  8. [C/C++] C++模板定义格式

    函数模板的格式: template <class 形参名,class 形参名,......> 返回类型 函数名(参数列表) { //函数体 } 类模板的格式为: template<c ...

  9. 【bzoj1738】[Usaco2005 mar]Ombrophobic Bovines 发抖的牛 Floyd+二分+网络流最大流

    题目描述 FJ's cows really hate getting wet so much that the mere thought of getting caught in the rain m ...

  10. BZOJ4804 欧拉心算(莫比乌斯反演+欧拉函数+线性筛)

    一通套路后得Σφ(d)μ(D/d)⌊n/D⌋2.显然整除分块,问题在于怎么快速计算φ和μ的狄利克雷卷积.积性函数的卷积还是积性函数,那么线性筛即可.因为μ(pc)=0 (c>=2),所以f(pc ...