#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. Java并发编程(二):volatile关键字

    volatile是Java虚拟机提供的轻量级的同步机制.volatile关键字有如下两个作用,一句话概括就是内存可见性和禁止重排序. 1)保证被volatile修饰的共享变量对所有线程总是可见的,也就 ...

  2. web语义化这个坑

    什么是wen语义化:https://www.zhihu.com/question/20455165 标签大全:http://www.w3school.com.cn/tags/tag_html.asp ...

  3. fgets汉字问题

    #include<stdio.h> #include <stdlib.h> #define N 10 int main(int argc, char *argv[]) { FI ...

  4. 认识Git与GitHub

    Git介绍 Git是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.相比CVS.SVN等版本控制工具,Git更加优秀,功能也更加强大.但是相对也难学. 使用Git来管理 ...

  5. 测试用例设计:PICT的安装及使用

    一.下载与安装 打开百度网页,搜索PICT,即可找到许多下载链接,点击这里,下载到桌面,点击安装.一直NEXT,安装路径保存在C盘: 二.PICT 使用 1.找到安装目录,即可看到以下内容 2.创建t ...

  6. Codeforces_714_A

    http://codeforces.com/problemset/problem/714/A 水,注意K的值. #include <iostream> using namespace st ...

  7. 关于AR眼镜的小结

    根据IDC(International Data Corporation,国际数据公司,IDC是全球著名的信息技术.电信行业和消费科技咨询.顾问和活动服务专业提供商)的报告,2018年AR和VR的产值 ...

  8. Codeforces 1175F The Number of Subpermutations (思维+rmq)

    题意: 求区间[l, r]是一个1~r-l+1的排列的区间个数 n<=3e5 思路: 如果[l,r]是一个排列,首先这里面的数应该各不相同,然后max(l,r)应该等于r-l+1,这就能唯一确定 ...

  9. 林大妈的JavaScript进阶知识(二):JS异步行为

    JavaScript 是单线程执行的 JavaScript运行在浏览器中.浏览器是多线程的,但只分配了其中一条给JavaScript,作为它的主线程.对于编码者来说,JavaScript是单线程的.因 ...

  10. UnityTips:不要在发布版本中实现OnGUI方法

    0x00 问题 不知道大家是否在调试Unity应用性能的时候发现过一条常见的Marker:UIEvents.IMGUIRenderOverlays. 很多情况下,这条叫做UIEvents.IMGUIR ...