hdu 4027
Can you answer these queries?
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 12193 Accepted Submission(s): 2892
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.
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.
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
19
7
6
The 36th ACM/ICPC Asia Regional
Shanghai Site —— Online Contest
此题需要开极大的线段树数组,并且要用long long。由于使用sqrt,所以可以利用当节点或区间内值都是1时就不再往下update,也算是lazy思想。
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
long long dur[15040000];
inline void pushup(int k)
{dur[k]=dur[k<<1]+dur[k<<1|1];}
inline void build(int s,int t,int k)
{
if(!(s^t)){
scanf("%I64d",&dur[k]);
return;
}int m=(s+t)>>1;
build(s,m,k<<1);
build(m+1,t,k<<1|1);
pushup(k);
}
inline void update(int s,int t,int k,int l,int r)
{
if(dur[k]==t-s+1)return;
if(!(s^t)){
dur[k]=sqrt(dur[k]);
return;
}int m=(s+t)>>1;
if(l<=m)update(s,m,k<<1,l,r);
if(m<r)update(m+1,t,k<<1|1,l,r);
pushup(k);
}
inline long long query(int s,int t,int k,int l,int r)
{
if(l<=s&&t<=r)return dur[k];
int m=(s+t)>>1;
long long res=0;
if(l<=m)res+=query(s,m,k<<1,l,r);
if(m<r)res+=query(m+1,t,k<<1|1,l,r);
return res;
}
int main()
{
int n,m,cas=0;
while(scanf("%d",&n)!=EOF){
build(1,n,1);
scanf("%d",&m);
printf("Case #%d:\n",++cas);
for(;m;m--){
int T,a,b;
scanf("%d%d%d",&T,&a,&b);
if(a>b)swap(a,b);
if(!T)update(1,n,1,a,b);
else printf("%I64d\n",query(1,n,1,a,b));
}puts("");
}
return 0;
}
hdu 4027的更多相关文章
- HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)
题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的 ...
- HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】
Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- HDU 4027(线段树)
HDU4027 题意:操作指令为0时,对区间[x,y]之间的数字进行开平方:指令为1的时候,对区间[x,y]之间的数字求和并输出: 思路:线段树处理就OK了,但是64位内的数最多开8次平方就为1了(开 ...
- Can you answer these queries? HDU 4027 线段树
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...
- V - Can you answer these queries? HDU - 4027 线段树 暴力
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和
Can you answer these queries? Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...
- hdu 4027 2011上海赛区网络赛G 线段树 成段平方根 ***
不能直接使用成段增减的那种,因为一段和的平方根不等于平方根的和,直接记录是否为1,是1就不需要更新了 #include<cstdio> #include<iostream> # ...
随机推荐
- SharePoint 2013 列表关于大数据的测试
本文主要介绍SharePoint列表库的效率问题,一直以来以为阙值5k,超过会线性下降,需要分文件夹存放:或许这是之前版本的描述,但是2013版本通过测试,真心不是这么一回事儿. 下面,简单介绍下自己 ...
- Android 开源框架Universal-Image-Loader完全解析(二)--- 图片缓存策略详解
转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/26810303),请尊重他人的辛勤劳动成果,谢谢! 本篇文章 ...
- HTTPS学习总结
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 21.0px Verdana; color: #393939 } span.s1 { } HTTPS学习总结 ...
- android 最详细的动画大全,包括如何在代码和在XML中使用
一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画 ...
- xcode 删除文件后编译会出现*** is missing from working copy
删除文件后 工程中会出现如图所示 如果你使用了svn管理工具 你就会看到如图所示 然后 选中 删除 就可以了 好了 多了 不多说了 最近比较忙 博客写的比较 少 等闲了 一定会 ...
- 【代码笔记】iOS-判断是否是iPhone5
一,代码. #import "RootViewController.h" // 判断是否是iPhone5 #define iPhone5 ([UIScreen instancesR ...
- iOS集成ijkplayer视频直播框架,遇到的bug和坑...
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 32.0px "Helvetica Neue"; color: #555555 } p. ...
- 《内容生产向视频过渡:Facebook收购QuickFire意欲何为?》有感
1月9日消息,Facebook周四表示,已收购位于加州圣迭戈的QuickFire Networks. 一.解决视频传输问题 QuickFire是一家开发视频内容发布设备和转码处理软件的创业公司,其创办 ...
- jquery 基础教程[温故而知新二]
子曰:“温故而知新,可以为师矣.”孔子说:“温习旧知识从而得知新的理解与体会,凭借这一点就可以成为老师了.“ 尤其是咱们搞程序的人,不管是不是全栈工程师,都是集十八般武艺于一身.不过有时候有些知识如果 ...
- spring定时器(一)
使用的是spring的quartz功能,需导入com.springsource.org.quartz.jar包. 此定时器无法重置定时时间,需要的话可查看:spring定时器(二) spring的be ...