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. Java进阶知识点:并发容器背后的设计理念

    一.背景 容器是Java编程中使用频率很高的组件,但Java默认提供的基本容器(ArrayList,HashMap等)均不是线程安全的.当容器和多线程并发编程相遇时,程序员又该何去何从呢? 通常有两种 ...

  2. hibernate 异常a different object with the same identifier value was already associated with the session

    在使用hibernate的时候发现了一个问题,记录一下解决方案. 前提开启了事务和事务间并无commit,进行两次save,第二次的时候爆出下面的异常a different object with t ...

  3. Redis 错误摘记篇

    yum安装的redis提示如下报错,大概意思就是配置文件和redis-server进程文件版本不一致.. [root@vm-10-104-28-24 yum.repos.d]# redis-serve ...

  4. 《JavaScript 高级程序设计》总结

    一.JS基本概念 1.命名规则 变量名区分大小写(test和Test是两个不同的变量名),标识符采用驼峰命名格式,即:第一个字母小写,剩下的每个有意义的单词首字母大写: 标识符第一个字符必须是以字母. ...

  5. ARKit----学习一

    一.ARKit的简介 开始进入正题吧 ARKit在iOS 11上推出的一个AR移动平台,支持A9以上的处理器,不支持模拟器.ARKit使用相机捕捉现实世界,使用SceneKit,SpriteKit或者 ...

  6. 20个实用的Linux命令

    20个实用的Linux命令 2016-04-16 程序员之家 1. 命令:sl (蒸汽机车) 你可能了解 ‘ls’ 命令,并经常使用它来查看文件夹的内容.但是,有些时候你可能会拼写成 ‘sl’ ,这时 ...

  7. 【APS.NET Core】- Razor Page 使用jqgrid实现分页功能

    本文将使用jqgrid在Razor Page中实现分页功能. 前台 List.cshtml代码如下: @page @model ListModel @{ Layout = "~/Pages/ ...

  8. DVD与CD区别

    经常听朋友说什么DVD什么CD什么的,不知道到底有什么区别,专门百度找了下,找到以下资料 ======================================================= ...

  9. 加密和数字签名工具GPG

    转载: 源文件位置:http://blog.chinaunix.net/uid-9525959-id-2001824.html GPG [功能]  GPG是加密和数字签名的免费工具,大多用于加密信息的 ...

  10. cmake & make

    大家都知道,写程序大体步骤为: 1.用编辑器编写源代码,如.c文件. 2.用编译器编译代码生成目标文件,如.o. 3.用链接器连接目标代码生成可执行文件,如.exe. 但如果源文件太多,一个一个编译时 ...