(线段树 区间查询更新) 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 ...
随机推荐
- jstatd - Virtual Machine jstat Daemon
jstatd [options] 参数:options 命令行参数,可以按任何顺序,但如果有多余的或者中有互斥的参数,最后制定的那个参数将有优先权 options: -nr 当一个存在的RMI Reg ...
- Tomcat数据库连接池配置
Tomcat数据库连接池配置 1. Server.xml的配置 (1)找到tomcat所在目录下的conf\server.xml文件 (2)在文件最后一个</host> ...
- tensor flow 的两种padding方式
https://segmentfault.com/a/1190000007846181
- Mysql delete操作
以下摘自官方文档:https://dev.mysql.com/doc/refman/5.7/en/insert.html 语法: DELETE [LOW_PRIORITY] [QUICK] [IGNO ...
- Java 命令行运行参数
Java在运行已编译完成的类时,是通过java虚拟机来装载和执行的,java虚拟机通过操作系统命令JAVA_HOME"bin"java –option 来启动,-option为虚拟 ...
- xpath定位--绝对与相对的定位
xpath定位--绝对与相对的定位: xpath定位即为xml路径语言,它是一种用来确定xml文档中某部分位置的语言,xpath基于xml的树状结构,提供在数据结构中找寻节点的能力 xpath的相对定 ...
- The value for the useBean class attribute is invalid.
报错如下: The value for the useBean class attribute com.JavaBeanTest is invalid. 解决方法: 在JavaBean代码中加入无参数 ...
- 对象池 object pool
对象池适用于: 对象的创建很耗时 对象频繁地释放再创建 对象池的实现:将释放的对象放进对象池中,在新建对象时,从对象池取对象 public class ObjectPool<T> wher ...
- 【校招面试 之 C/C++】第27题 C++ 智能指针(三)之 unique_ptr
auto_ptr<string> p1(new string ("auto") : //#1 auto_ptr<string> p2; //#2 p2 = ...
- 查看sqlserver所有存储过程、视图等脚本语句
sqlserver上右击——任务——生成脚本 下一步——选择特定数据库对象 导出即可