#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. 1、OSI参考模型

    网络的层次模型:Core layer (核心层):高速转发,不建议做策略  Distribution layer (分布层,汇聚层):基于策略连接(路由控制,安全策略)Access layer (接入 ...

  2. Magicodes.IE 2.0发布

    Magicodes.IE 2.0发布 Magicodes.IE是我们维护的开源的导入导出通用库,去年年底已加入NCC开源组织. Github地址:https://github.com/xin-lai/ ...

  3. 关于java String类的getBytes(String charsetName)和String(byte[] bytes, String charsetName)

    public byte[] getBytes(Charset charset) Encodes this String into a sequence of bytes using the given ...

  4. 全局对象的构造函数会在main函数之前执行?

    #include <iostream> using namespace std; class CTest { public: CTest() { cout << "构 ...

  5. python学习记录(八)

    0910--https://www.cnblogs.com/fnng/archive/2013/04/28/3048356.html Python异常 Python用异常对象(exception ob ...

  6. CCF_201409-1_相邻数对

    水. #include<iostream> #include<cstdio> #include<algorithm> using namespace std; in ...

  7. 2020你还不会Java8新特性?

    Java8(1)新特性介绍及Lambda表达式 前言: 跟大娃一块看,把原来的电脑拿出来放中间看视频用 --- 以后会有的课程 难度 深入Java 8 难度1 并发与netty 难度3 JVM 难度4 ...

  8. php扩展模块的安装

    PHP的扩展模块安装 模块安装总则: 进入到ext/目录下对应的模块 执行/usr/local/php/bin/phpize 也就是执行一遍phpize生成编译文件 ./configure --wit ...

  9. angular 控件间的通信

    先引入 设置meta元素 http://blog.sina.com.cn/s/blog_51048da70101cgea.html //设置 虚拟窗口的大小等于设备的大小 <meta name= ...

  10. AtCoder Beginner Contest 156

    https://atcoder.jp/contests/abc156/tasks A - Beginner #include <bits/stdc++.h> #define ll long ...