Can you answer these queries?-HDU4027 区间开方
题意:
给你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 区间开方的更多相关文章
- Can you answer these queries?---hdu4027
题目链接 有n个数:当操作为1时求L到R的和: 当操作为0时更新L到R为原来的平方根: 不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底 ...
- (线段树 区间查询更新) Can you answer these queries? -- hdu--4027
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...
- HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】
Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Atcoder Beginner Contest151E(排列组合)
排列组合 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ; ]; long lo ...
- zabbix-agent不能启动:配置文件出现特殊字符导致
问题如下: 定位查找问题: 命令:journalctl -xe [重点] 图中可见错误信息在zabbix_agent配置文件中的“hostname=”中不能出现特殊字符,我出错的原因是写成了:hos ...
- php自动读取文件夹下所有图片
$path = 'xxxxx';///当前目录$handle = opendir($path); //当前目录while (false !== ($file = readdir($handle))) ...
- jQuery之绑定焦点事件(焦点事件失效)
在使用jQuery绑定事件时,若某个事件不存在,则该事件后 绑定的事件均失效: 如图所示,若失去焦点事件checkEmail不存在, 会导致后面的事件checkMobile,和事件checkBirth ...
- HTML使用链接调用本地exe文件
一,win+r打开注册表,输入regedit进入注册表 二,在注册表左边最上面HKEY_CLASSES_ROOT那个树右键新建项.该项的名称自己命名,其实该名称也是协议的名称. 我们调用的时候就是根据 ...
- 将信息存储在claim中,通过扩展AbpSession取出
一.将信息存储到claim中 claims.AddRange(new[] { //新增身份,添加租户id new Claim("RoleName","管理员111&quo ...
- put、patch与post区别
idempotent 幂等的 如果一个方法重复执行多次,产生的效果是一样的,那就是idempotent的: idempotent的意思是如果相同的操作再執行第二遍第三遍,結果還是一樣. POST方法 ...
- python opencv:代码执行时间计算
t1 = cv2.getTickCount() # ...... t2 = cv2.getTickCount() # 计算花费的时间:毫秒 time = (t2-t1) / cv2.getTickFr ...
- Springboot学习:核心配置文件
核心配置文件介绍 SpringBoot使用一个全局配置文件,配置文件名是固定的 application.properties application.yml 配置文件的作用:修改SpringBoot自 ...
- 【代码总结】GD库中简单的验证码
大体思路: 代码部分: <?php //1.创建画布 $img = imagecreatetruecolor(100,30); //2.设置颜色 值越小,颜色越深 $color1 = image ...