HDU4027 线段树
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
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.
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.
19
7
6
//因为题目中所有和不超过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 线段树的更多相关文章
- hdu-4027线段树练习
title: hdu-4027线段树练习 date: 2018-10-10 18:07:11 tags: acm 算法 刷题 categories: ACM-线段树 # 概述 这道线段树的题可以说是我 ...
- hdu4027线段树
https://vjudge.net/contest/66989#problem/H 此题真是坑到爆!!说好的四舍五入害我改了一个多小时,不用四舍五入!!有好几个坑点,注意要交换l,r的位置,还有输出 ...
- HDU4027(线段树单点更新区间)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- BZOJ3211花神游历各国-线段树&树状数组-(HDU4027同类型)
(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 题意:BZOJ HDU 原题目描述在最下面. 两种操作,1:把区间的数字开方一次,2:区间求和. 思路: 线段树: 显然不能暴力 ...
- HDU4027 Can you answer these queries? 线段树
思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...
- hdu4027(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 线段树功能:区间修改,区间求和. 分析:因为每个数至多开6次平方就变1了,所以对于每一段全为1的 ...
- Can you answer these queries?(HDU4027+势能线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
随机推荐
- FastJson 序列化与反序列化一些说明
最近所属的组需要对接一些征信结构,就涉及到很多中的数据格式,而springmvc中使用的是jackson作为@ResponseBody的依赖jar 但是个人认为fastkson的性能要高于jackso ...
- 【转】跨平台移动端开发框架NativeScript 发布正式版本
原文:http://news.cnblogs.com/n/520865/ Nativescript 项目地址:http://www.telerik.com/nativescript “一次编码,处处运 ...
- Apache POI:Excel读写库
1)Apache POI 简介 Apache POI是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写 ...
- LeetCode 135——分发糖果
1. 题目 2. 解答 初始化左序奖赏全为 1,从左往右遍历,如果右边的人评分比左边高,右边奖赏比左边奖赏增 1. 初始化右序奖赏全为 1,从右往左遍历,如果左边的人评分比右边高,左边奖赏比右边奖赏增 ...
- 十 Writing YARN Applications
本节介绍: 使用yarn 高级提交写yarn应用程序.其实已经yarn底层API.MR计算框架对底层的API实现了封装. 高级提交指直接使用yarn的三种接口来提交应用程序: 1)YarnCl ...
- Thunder团队Beta周贡献分分配结果
小组名称:Thunder 项目名称:爱阅app 组长:王航 成员:李传康.翟宇豪.邹双黛.苗威.宋雨.胡佑蓉.杨梓瑞 分配规则 规则1:基础分,拿出总分的20%(8分)进行均分,剩下的80%(32分) ...
- spring框架(1)— 依赖注入
依赖注入 spring核心容器就是一个超级大工厂,所以的对象(数据源.hibernate SessionFactory等基础性资源)都会被当做spring核心容器的管理对象——spring把容器中的一 ...
- c++:error2019,无法解析的外部命令blabla~
出现这个原因的问题汇总: 1,相应的附加库没有包含进去,注意附加库的目录是 / 2,函数没有与之对应的类,却在main中以某一类的对象调用了该方法. 其实,当错误中显示fun()成为无法解析的外部命令 ...
- shit antd & Merry Christmas bug
shit antd & Merry Christmas bug https://github.com/ant-design/ant-design/issues/13098 antd 玩大了? ...
- 【bzoj3312】[Usaco2013 Nov]No Change 状态压缩dp+二分
题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 ...