题意:

给你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. 洛谷 P2058 海港(模拟)

    题目链接:https://www.luogu.com.cn/problem/P2058 这是一道用手写队列模拟的一道题,没有什么细节,只是注意因为数不会很大,所以直接用数作为数组下标即可,不用用map ...

  2. springboot+mybatis报错Invalid bound statement (not found)

    今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql:原因是程序没有把.xml文件编译 ...

  3. docker中安装mysql遇到的问题

    在虚拟机上用docker安装了一个mysql最新版,然后在本地用sqlyog区连接报错‘plugin  cachin_sha2_password  could  not  be  loaded’经过上 ...

  4. Web基础了解版07-EL表达式-运算符-11个隐式对象

    EL EL(Expression Language)是JSP内置的表达式语言,用以访问页面的上下文以及不同作用域中的对象 ,取得对象属性的值,或执行简单的运算或判断操作.EL在得到某个数据时,会自动进 ...

  5. __dirname和__filename和process.cwd()三者的区别

    1.process cwd() 方法返回 Node.js 进程当前工作的目录 例:我在F:\自己的文件\自己在网上学习的知识点\node学习\node-API\process 这个文件加下面创建了一个 ...

  6. opencv:绘制图像直方图

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...

  7. spring 基于xml的申明式AspectH中的后置通知的返回值获取

    spring 基于xml的申明式AspectH中的后置通知的返回值获取 1. 配置文件 <aop:config> <aop:aspect ref="myAspect&quo ...

  8. Python函数基础进阶

    函数参数的另一种使用方式 def print_info(name,age): print("Name: %s" %name) print("age: %d" % ...

  9. dp(小猪存钱罐)

                      B - Piggy-Bank 在acm能够做任何事情之前, 必须编制预算并获得必要的财政支持.这一行动的主要收入来自IBM.这个想法其实很简单,每当一些会员有一点小 ...

  10. datename()计算一个日期是星期几