(线段树 区间查询更新) Can you answer these queries? -- hdu--4027
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4027
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
const int N = ;
using namespace std; #define Lson r<<1
#define Rson r<<1|1
#define mid a[r].Mid() struct node
{
int L, R;
long long sum;
int Mid()
{
return (L+R)>>;
}
int len()
{
return (R-L+);
};
} a[N<<]; void BuildTree(int r, int L, int R)
{
a[r].L=L, a[r].R=R; if(L==R)
{
scanf("%lld", &a[r].sum);
return ;
} BuildTree(Lson, L, mid);
BuildTree(Rson, mid+, R); a[r].sum = a[Lson].sum + a[Rson].sum;
} void Oper(int r, int L, int R)
{
if(a[r].len() == a[r].sum)
return ; if(a[r].L==a[r].R)
{
a[r].sum = (long long)sqrt(a[r].sum*1.0);
return ;
} if(R<=mid)
Oper(Lson, L, R);
else if(L>mid)
Oper(Rson, L, R);
else
{
Oper(Lson, L, mid);
Oper(Rson, mid+, R);
} a[r].sum = a[Lson].sum + a[Rson].sum;
} long long Query(int r, int L, int R)
{
if(a[r].L==L && a[r].R==R)
return a[r].sum; if(R<=mid)
return Query(Lson, L, R);
else if(L>mid)
return Query(Rson, L, R);
else
{
return Query(Lson, L, mid) + Query(Rson, mid+, R);
}
} int main()
{
int n, m, t=;
while(scanf("%d", &n)!=EOF)
{ BuildTree(, , n); int L, R, e; scanf("%d", &m); printf("Case #%d:\n", t++);
while(m--)
{
scanf("%d%d%d", &e, &L, &R); if(L>R)
swap(L, R);
if(e==)
Oper(, L, R);
else
{
printf("%lld\n", Query(, L, R));
}
} printf("\n");
}
return ;
}
(线段树 区间查询更新) Can you answer these queries? -- hdu--4027的更多相关文章
- V - Can you answer these queries? HDU - 4027 线段树 暴力
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
- Can you answer these queries? HDU 4027 线段树
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...
- 【DFS序+线段树区间更新区间求最值】HDU 5692 Snacks
http://acm.hdu.edu.cn/showproblem.php?pid=5692 [思路] 每更新一个点,子树的所有结点都要更新,所以是区间更新 每查询一个点,子树的所有结点都要查询,所以 ...
- 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 ...
- 线段树 SP1716 GSS3 - Can you answer these queries III
SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...
- 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国
SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...
- 线段树 SP1043 GSS1 - Can you answer these queries I
SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...
- Can you answer these queries? HDU - 4027(线段树+技巧)
题意:给一个数组序列, 数组长度为100000 两种操作: 一种操作是将某一个固定区间所有数开方(向下取整) 另一种操作是询问某个区间的所有数字之和. 由于数不超过263,因此开个七八次就变成1,由于 ...
- Can you answer these queries? HDU - 4027 有点坑
#include<iostream> #include<cstring> #include<cstdio> #include<math.h> #incl ...
随机推荐
- 富文本编辑器-UEditor
官方网址:http://ueditor.baidu.com/website/index.html 下载地址:http://ueditor.baidu.com/website/download.html ...
- 概率论与数理统计 Q&A:
--------------------------------- 大数定律:大量样本数据的均值(样本值之和除以样本个数),近似于随机变量的期望(标准概率*样本次数).(样本(部分)趋近于总体)中心极 ...
- Spring Boot中启动HTTPS
一,生成https 的证书 1,在相应的根目录下 keytool -genkey -alias tomcat -storetype PKCS12 -keyalg RSA -keysize -keyst ...
- The requested resource (/) is not available解决办法
The requested resource (/) is not available HTTP Status 404(The requested resource is not available) ...
- git基本命令之删除撤销操作
1.将删除文件恢复--撤销所删除的文件git checkout 文件名 2.git resetgit reset --hard commitID(或某个节点)----强制切换到某个点,会导致所修改的内 ...
- java列表转成 int[] 的格式
java 稀疏矩阵中输入的索引系列和对应的值系列需要用 int[] r_indices = new int[featureIdxList.size()]; 的数据格式. 但是实际中可能实现没法确定 f ...
- 岭回归和lasso回归(转)
回归和分类是机器学习算法所要解决的两个主要问题.分类大家都知道,模型的输出值是离散值,对应着相应的类别,通常的简单分类问题模型输出值是二值的,也就是二分类问题.但是回归就稍微复杂一些,回归模型的输出值 ...
- go 格式化时间戳
func main() { //获取时间戳 timestamp := time.Now().Unix() fmt.Println(timestamp) //格式化为字符串,tm为Time类型 tm : ...
- python没有switch,可以用字典来替代
python没有switch,是因为可以用字典来替代,具体方法如下: def add(x,y): print(x+y)def subtraction(x,y): print(x-y)def multi ...
- MyBatis一对一查询
---------------------siwuxie095 MyBatis 一对一查询 以订单和用户为例,即 相对订 ...