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 ...
随机推荐
- Qt QQuickView设置成无边框无标题栏
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> ...
- 507,介绍一下标准的css盒子模型?低版本ie的盒子模型有什么不同的?
有两种,IE盒子模型,另外是W3C盒子模型: 盒模型都包括:内容(content),填充(padding),边界(margin),边框(border): 区别:IE的content部分吧border和 ...
- Azure IoT Hub 十分钟入门系列 (1)- 10分钟带你了解Azure IoT Hub 并创建IoT Hub
建议您先对<Azure 上 IoT 整体解决方案概览 >进行了解. 本文主要分享一个案例: 10分钟-了解Azure IoT Hub并创建Azure IoT Hub 本文主要有如下内容: ...
- 初始css一
初始CSS 一.form表单补充 form表单关键性的属性补充 form表单 关键性的属性 action 控制的是数据的提交路径 1.不写 默认是朝着当前页面所在的地址提交 2.全路径 3.后缀(/i ...
- Python基础数据类型以及对应方法
数据类型 不可变数据(四个):Number(数字).String(字符串).Tuple(元组).Sets(集合):可哈希 可变数据(两个):List(列表).Dictionary(字典).不可哈希 字 ...
- PTA喊山
喊山 喊山,是人双手围在嘴边成喇叭状,对着远方高山发出“喂—喂喂—喂喂喂……”的呼唤.呼唤声通过空气的传递,回荡于深谷之间,传送到人们耳中,发出约定俗成的“讯号”,达到声讯传递交流的目的.原来它是彝族 ...
- 洛谷 P1880 [NOI1995]石子合并(区间DP)
嗯... 题目链接:https://www.luogu.org/problem/P1880 这道题特点在于石子是一个环,所以让a[i+n] = a[i](两倍长度)即可解决环的问题,然后注意求区间最小 ...
- 【Go语言系列】1.1、GO语言简介:什么是GO语言
一.Go的起源 Go语言的所有设计者都说,设计Go语言是因为 C++ 给他们带来了挫败感.在 Google I/O 2012 的 Go 设计小组见面会上,Rob Pike 是这样说的: 我们做了大量的 ...
- matplotlib显示AttributeError: 'module' object has no attribute 'verbose'
解决办法:file-settings-tools-python scientific,将show plots in toolwindow前面的对号去掉即可.
- mpvue路由传参报错Cannot read property 'query' of undefined
在mpvue编写的小程序项目中,页面跳转间我希望通过编程式导航传递些参数 传参页面代码: this.$router.push({path:'/pages/login/changePassword/ma ...