题意:

给你n个数,两个操作,0为区间开方,1为区间求和

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027

思路:

如果当该区间的数都为1,我们没必要进行开方操作,因为1开方还是1,否则找到每个叶子节点,进行开方操作

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MAXN=1e5+;
const int INF=0x7fffffff;
typedef long long ll;
ll lazy[MAXN<<],tree[MAXN<<];
void push_up(int node)
{
tree[node]=tree[node<<]+tree[node<<|];
}
void build(int node,int l,int r)
{
if(l==r)
{
scanf("%lld",&tree[node]);
return ;
}
int mid=(l+r)>>;
build(node<<,l,mid);
build(node<<|,mid+,r);
push_up(node);
} void update(int node,int l,int r,int x,int y)
{
//区间的长度等于区间内所有数之和则说明所有数都为1
if(x<=l&&y>=r&&(r-l+==tree[node]))
{
return;
}
if(l==r)
{
tree[node]=(ll)sqrt(tree[node]);return;
}
int mid=(l+r)>>;
if(x<=mid)
update(node<<,l,mid,x,y);
if(y>mid)
update(node<<|,mid+,r,x,y);
push_up(node);
}
ll query(int node,int l,int r,int x,int y)
{
if(x<=l&&y>=r)
{
return tree[node];
}
ll ans=;
int mid=(l+r)>>;
if(x<=mid)ans+=query(node<<,l,mid,x,y);
if(y>mid)ans+=query(node<<|,mid+,r,x,y);
return ans;
}
int main()
{
int n;
int case_=;
while(scanf("%d",&n)!=EOF)
{
printf("Case #%d:\n",++case_);
build(,,n);
int k;scanf("%d",&k);
for(int i=;i<=k;i++)
{
int op;scanf("%d",&op);
int x,y;
if(!op)
{
scanf("%d%d",&x,&y);update(,,n,min(x,y),max(x,y));
}
else
{
scanf("%d%d",&x,&y);
printf("%lld\n",query(,,n,min(x,y),max(x,y)));
} }printf("\n");
} return ;
}

Can you answer these queries?-HDU4027 区间开方的更多相关文章

  1. Can you answer these queries?---hdu4027

    题目链接 有n个数:当操作为1时求L到R的和: 当操作为0时更新L到R为原来的平方根: 不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底 ...

  2. (线段树 区间查询更新) Can you answer these queries? -- hdu--4027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...

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

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

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

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

  5. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

  6. hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)

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

  7. HDU 4027 Can you answer these queries? (线段树区间修改查询)

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

  8. kuangbin专题七 HDU4027 Can you answer these queries? (线段树)

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

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

随机推荐

  1. PHPStorm设置Ctrl+滚轮调整字体大小

    1.点击左上角的File,再点击setting: 2.Editor->General,选择Change font size (Zoom) with Ctrl+Mouse Wheel: 3.点击O ...

  2. dk7和jdk8的一些新特性

    本文是我学习了解了j 的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwork/java/javase/jdk7-relnotes- ...

  3. Scala实现网站流量实时分析

    之前已经完成zookeeper集群.Hadoop集群.HBase集群.Flume.Kafka集群.Spark集群的搭建:使用Docker搭建Spark集群(用于实现网站流量实时分析模块),且离线分析模 ...

  4. 6、Java运算符

    运算符的分类 算数运算符 二元运算符 算术运算符中 = - * / % 属于二元运算符,二元运算符指的是需要两个操作数才能完成的运算的运算术. 整数运算规则 1.如果两个操作数有一个为Long,则结果 ...

  5. HDU 6631 line symmetric 计算几何

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6631 题意:共\(T\)组数据,每组数据给出\(n\)个点的坐标,这\(n\)个点按顺序给出,相邻的点 ...

  6. 【WPF学习】第十四章 事件路由

    由上一章可知,WPF中的许多控件都是内容控件,而内容控件可包含任何类型以及大量的嵌套内容.例如,可构建包含图形的按钮,创建混合了文本和图片内容的标签,或者为了实现滚动或折叠的显示效果而在特定容器中放置 ...

  7. bm坏字符 , Horspool算法 以及Sunday算法的不同

    bm坏字符 , Horspool算法 以及Sunday算法的不同 一.bm中的坏字符规则思想 (1)模式串与主串从后向前匹配 (2)发现坏字符后,如果坏字符不存在于模式串中:将模式串的头字符与坏字符后 ...

  8. dfs序与求子树子节点(染了色)的个数

    https://blog.csdn.net/hpu2022/article/details/81910490 https://blog.csdn.net/qq_39670434/article/det ...

  9. java.lang.String和java.util.NClob互相转换

    //NClob或Clob转String类型 public String clob2Str(NClob nclob) throws Exception { String content = " ...

  10. Cookie API介绍

    一.Java提供的操作Cookie的API Java中的javax.servlet.http.Cookie类用于创建一个Cookie Cookie类的主要方法 No. 方法 类型 描述 Cookie( ...