#include<iostream>
#include<cstring>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
ll a[N];
int n,m;
int op,l,r;
struct node
{
ll l,r;
ll sum;
}tr[N*];
void build(int root,int l, int r)
{
tr[root]={l,r};
tr[root].sum=;
if(l==r)
{
tr[root].sum=a[l];
return;
}
int mid=l+r>>;
build(root<<,l,mid);
build(root<<|,mid+,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
void update(int root,int l,int r)
{
if(l>tr[root].r||tr[root].l>r)
return;
if (tr[root].sum==(tr[root].r-tr[root].l + ))
return;
if (tr[root].l==tr[root].r)
{
tr[root].sum=sqrt(tr[root].sum);
return;
}
int mid=tr[root].l+tr[root].r>>;
update(root<<,l,r);
update(root<<|,l,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
ll Query(int root,int l,int r)
{
if (l>tr[root].r||tr[root].l>r)
return ;
if (l<=tr[root].l&&tr[root].r<=r)
return tr[root].sum;
int mid=tr[root].l+tr[root].r>>;
ll res=;
res+=Query(root<<,l,r);
res+=Query(root<<|,l,r);
return res;
}
int main()
{
int cnt=;
while(~scanf("%d",&n))
{
printf("Case #%d:\n",++cnt);
for (int i=;i<=n;i++)
scanf("%lld",&a[i]);
scanf("%d",&m);
build(,,n);
while (m--)
{
scanf("%d%d%d",&op,&l,&r);
if(l>r)
swap(l,r);
if(op==)
update(,l,r);
else
printf("%lld\n",Query(,l,r));
}
printf("\n");
}
return ;
}

Can you answer these queries? HDU - 4027 有点坑的更多相关文章

  1. Can you answer these queries? HDU 4027 线段树

    Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...

  2. V - Can you answer these queries? HDU - 4027 线段树 暴力

    V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...

  3. Can you answer these queries? HDU - 4027 (线段树,区间开平方,区间求和)

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  4. Can you answer these queries? HDU - 4027(线段树+技巧)

    题意:给一个数组序列, 数组长度为100000 两种操作: 一种操作是将某一个固定区间所有数开方(向下取整) 另一种操作是询问某个区间的所有数字之和. 由于数不超过263,因此开个七八次就变成1,由于 ...

  5. H - Can you answer these queries? ( POJ - 3264 )

    H - Can you answer these queries? HDU - 4027   思路: 一眼思路:线段树区间修改,区间查询. 发现bug:区间的sqrt无法实现,所以还是相当于对区间的每 ...

  6. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

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

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

  8. HDU 4027 Can you answer these queries?(线段树区间开方)

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

  9. 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 ...

随机推荐

  1. Linux 下tomcat 的重新启动

    在 Linux 系统下,重启 Tomcat 如何使用命令操作? 1.首先,进入 Tomcat 的 bin 目录 cd /usr/local/tomcat/bin 2.使用Tomcat关闭命令 ./sh ...

  2. js关于时间(date)的比较

    之前在工作上遇到一个问题:使用一些时间插件,如果有俩个时间,要判断结束时间和开始时间的大小?后来就查找了一些资料,这边整理出俩个比较简便的方法. 在这我拿 laydate.js 这个插件来举例: 首先 ...

  3. Django自动化测试平台项目案例

    引言 在项目组待了近半年时间,根据自己的感受和体验,做了一个辅助测试的工具(数据预报平台),主要目的是针对目前项目接口文档缺失,自动化预报脚本无法可视化,资源循环利用,统一管理化. 业务背景 我们项目 ...

  4. ATL的GUI程序设计(1)

    from:http://blog.titilima.com/atlgui-1.html 第一章 不能免俗的"Hello, World!" 在这一章里,就像所有的入门级教程一样,我也 ...

  5. qt creator源码全方面分析(2-6)

    目录 User Interface Text Guidelines 语法和风格 标点 编写工具提示tooltips 编写消息 UI文本大写 使用书本样式大写 使用句子样式大写 准备本地化 标记UI文本 ...

  6. CCF_201604-4_游戏

    bfs,首先记录危险方格的时间,因为100时间之后,所有方格均不危险,所以最短时间的最大值为300,记录每个坐标每个时间的状态,直接bfs即可. #include<cstdio> #inc ...

  7. jmeter接口测试(登录、注册)

    Jmeter 进行接口测试流程: Jmeter 的下载地址:http://jmeter.apache.org/download_jmeter.cgi 下面举例说明使用流程,有两种参数传递的方式,我们以 ...

  8. office2010无法卸载问题

    普通的卸载方式有: 1.从开始进入控制面板卸载程序,找到office2010并卸载. 2.运用软件管家等强力卸载电脑中的软件. 其他的卸载方式: 1).通过安装windows installer cl ...

  9. 1236 - Pairs Forming LCM

    1236 - Pairs Forming LCM   Find the result of the following code: long long pairsFormLCM( int n ) {  ...

  10. JS求1到100的累计值

    sum=0 for(i=1;i<=100;i++) { sum+=i } alert(sum)   作者:kerwin-chyl 文章链接:https:////www.cnblogs.com/k ...