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.

InputThe 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 2 63
  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. 
OutputFor 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 题意:就是它的每次操作是将一段区间的所有数都开一次平方,这个好像分块的时候也做过一次。
题解:因为一个数经过几次平方根就会GG变为1,然后就只需要记录这段区间是否为r-l+1即可。
是的话就不需要继续开根好了,否则就暴力下去,各个数开平方,就没了,每个数平均5次暴力,
然后就是普通线段树了,复杂度近似为O(n log n)
 #include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
const int MAXN=;
typedef long long LL;
long long a[MAXN],tree[MAXN*];
int x,y,z,q,n,t;
using namespace std; void build(int l,int r,int p)
{
if (l==r) tree[p]=a[l];
else
{
int mid=(l+r)>>;
build(l,mid,p*);
build(mid+,r,p*+);
tree[p]=tree[p*]+tree[p*+];
}
}
LL query(int l,int r,int p,int x,int y)
{
if (l==x&&r==y) return tree[p];
else
{
int mid=(l+r)>>;
LL res;
if (y<=mid) res=query(l,mid,p*,x,y);
else if(x>=mid+) res=query(mid+,r,p*+,x,y);
else
{
res=query(l,mid,p*,x,mid);
res=res+query(mid+,r,p*+,mid+,y);
}
return res;
}
}
void change(int l,int r,int p,int x,int y)
{
if (l==r) tree[p]=LL(sqrt(tree[p]));
else
{
if (tree[p]!=(r-l+))
{
int mid=(l+r)>>;
if (y<=mid) change(l,mid,p*,x,y);
else if (x>=mid+) change(mid+,r,p*+,x,y);
else
{
change(l,mid,p*,x,mid);
change(mid+,r,p*+,mid+,y);
}
tree[p]=tree[p*]+tree[p*+];
}
}
}
int main()
{
t=;
while (~scanf("%d",&n))
{
memset(tree,,sizeof(tree));
memset(a,,sizeof(a));
printf("Case #%d:\n",++t);
for (int i=;i<=n;i++)
scanf("%lld",&a[i]);
build(,n,);
scanf("%d",&q);
for (int i=;i<=q;i++)
{
scanf("%d%d%d",&x,&y,&z);
if (y>z) swap(y,z);
if (x) printf("%lld\n",query(,n,,y,z));
else change(,n,,y,z);
}
printf("\n");
}
}

hdu4027 开方,记录的更多相关文章

  1. Can you answer these queries?-HDU4027 区间开方

    题意: 给你n个数,两个操作,0为区间开方,1为区间求和 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 思路: 如果当该区间的数都为1,我们没必要 ...

  2. BZOJ 3038: 上帝造题的七分钟2【线段树区间开方问题】

    3038: 上帝造题的七分钟2 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1469  Solved: 631[Submit][Status][Dis ...

  3. 常用sql 全记录(添加中)

    -- 数据库SQL总结中........... --SQL分类: (CREATE,ALTER,DROP,DECLARE) ---DDL—数据定义语言(SELECT,DELETE,UPDATE,INSE ...

  4. hdu-4027线段树练习

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

  5. Oracle分析函数、窗口函数简单记录汇总

    一.分析函数.窗口函数一般形式 1.分析函数的形式分析函数带有一个开窗函数over(),包含三个分析子句:分组(partition by), 排序(order by), 窗口(rows) ,他们的使用 ...

  6. LOJ #6281. 数列分块入门 5-分块(区间开方、区间求和)

    #6281. 数列分块入门 5 内存限制:256 MiB时间限制:500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 5   题目描述 给出 ...

  7. HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】

    Can you answer these queries? Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & ...

  8. MATLAB常用指令记录

    help + 'command name' % 查询指令用法 Ctrl + Break % 强制终止程序运行 Shift + Enter % command window下换行不运行指令 M'; % ...

  9. 《机器学习实战》——k-近邻算法Python实现问题记录(转载)

    py2.7 : <机器学习实战> k-近邻算法 11.19 更新完毕 原文链接 <机器学习实战>第二章k-近邻算法,自己实现时遇到的问题,以及解决方法.做个记录. 1.写一个k ...

随机推荐

  1. 利用WHID为隔离主机建立隐秘通道

    0 引言 从2014年BADUSB出现以后,USB-HID攻击就这一直被关注,且具争议.争议的焦点是USB-HID的实战效果过于“鸡肋”,无论从早期的BADUSB,还是到后来的各种USB-HID设备, ...

  2. 从服务器端获取列和数据动态创建Ext.grid.EditorGridPanel

    1.添加列的方法 var addColumn = function(){ this.fields = ''; this.columns = ''; this.addColumns=function(n ...

  3. django框架(View)

    -------------------URLconf-------------------1.设置 1.在settings.py文件中通过ROOT_URLCONF指定根级url的配置 2.urlpat ...

  4. [js高手之路]深入浅出webpack系列1-安装与基本打包用法和命令参数

    webpack,我想大家应该都知道或者听过,Webpack是前端一个工具,可以让各个模块进行加载,预处理,再进行打包.现代的前端开发很多环境都依赖webpack构建,比如vue官方就推荐使用webpa ...

  5. LVS-NAT搭建HTTP及HTTPS

    author:JevonWei 版权声明:原创作品 搭建NAT模式的HTTP环境 网络拓扑图如下 网络环境 RS1 192.168.198.138 RS2 192.168.198.120 LVS: D ...

  6. Java内存溢出分析方法(Eclipse Memory Analyzer 使用简单入门)

    转载至:http://outofmemory.cn/java/jvm/OutOfMemoryError-analysis 工具 安装Memory Analyse Tools(MAT) 工具, 可以直接 ...

  7. mysql:Linux系统下mysql5.6的安装卸载

    1.1. 下载rpm包 要使用yum 安装mysql,需要mysql的yum仓库,先从官网下载适合你系统的仓库 http://dev.mysql.com/downloads/repo/yum/ 我的是 ...

  8. Ibatis XML 配置文件注释引起错误及解决方案

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp35 Ibatis XML 配置文件注释引起错误及解决方案 最近在使用Iba ...

  9. 图论中DFS与BFS的区别、用法、详解?

    DFS与BFS的区别.用法.详解? 写在最前的三点: 1.所谓图的遍历就是按照某种次序访问图的每一顶点一次仅且一次. 2.实现bfs和dfs都需要解决的一个问题就是如何存储图.一般有两种方法:邻接矩阵 ...

  10. 201521123016《Java设计与程序》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 1.clone方法 1.1 Object对 ...