H - Can you answer these queries? - (区间查询更新)
#pragma comment(linker, "/STACK:102400000,102400000")
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std; #define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R const int maxn = ; struct Tree
{
int L, R;
long long sum;
int Mid(){return (L+R)/;}
int Len(){return (R-L+);}
}tree[maxn*];
long long val[maxn]; void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R; if(L == R)
{
tree[root].sum = val[L];
return ;
} Build(Lson);
Build(Rson); tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
}
void Insert(int root, int L, int R)
{
if(tree[root].Len() == tree[root].sum)
return ;
if(tree[root].L == tree[root].R)
{
tree[root].sum = (long long)sqrt(tree[root].sum*1.0);
return ;
} if(R <= tree[root].Mid())
Insert(root<<, L, R);
else if(L > tree[root].Mid())
Insert(root<<|, L, R);
else
{
Insert(Lson);
Insert(Rson);
} tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
}
long long Query(int root, int L, int R)
{
if(tree[root].L == L && tree[root].R == R)
return tree[root].sum; if(R <= tree[root].Mid())
return Query(root<<, L, R);
else if(L > tree[root].Mid())
return Query(root<<|, L, R);
else
return Query(Lson)+Query(Rson);
} int main()
{
int i, N, M, t=; while(scanf("%d", &N) != EOF)
{
for(i=; i<=N; i++)
scanf("%lld", &val[i]);
Build(, , N); scanf("%d", &M); int c, a, b;
long long ans; printf("Case #%d:\n", t++);
while(M--)
{
scanf("%d%d%d", &c, &a, &b);
if(a > b)swap(a, b);
if(c == )
Insert(, a, b);
else
{
ans = Query(, a, b);
printf("%lld\n", ans);
}
}
printf("\n");
} return ; }
H - Can you answer these queries? - (区间查询更新)的更多相关文章
- H - Can you answer these queries? ( POJ - 3264 )
H - Can you answer these queries? HDU - 4027 思路: 一眼思路:线段树区间修改,区间查询. 发现bug:区间的sqrt无法实现,所以还是相当于对区间的每 ...
- SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)
GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...
- 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 ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- Can you answer these queries?
Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & ...
- hdu4027Can you answer these queries?【线段树】
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】
Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & ...
- 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 ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
随机推荐
- html.day01
1.web标准: 1. 结构 (xhtml) 2. 表现(css) 3.行为(js) html 超文本标记语言 xhtml (严格型超文本标记语言) 2.规范: 1. 所有标签(标记)都要 ...
- leetcode修炼之路——350. Intersection of Two Arrays II
题目如下: Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2 ...
- c# 使用递归 循环遍历导航树结构 并解析
1.数据书库结构 1 家用电器 0 一级菜单 2 手机.数码.京东通信 0 一级菜单 3 电脑.办公 0 一级菜单 4 家具.家居.厨房 0 一级菜单 5 男装.女装.童装.内衣 0 一级菜单 6 个 ...
- 抓取锁的sql语句-第二次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句 CUR_LOCK SYS ...
- IOS常用CGRect的交错,边缘,中心的检测
转自:http://tsyouaschen.iteye.com/blog/1946957 判断给定的点是否被一个CGRect包含,可以用CGRectContainsPoint函数 BOOL conta ...
- 初涉JavaScript模式 (9) : 函数 【常用方式】
回调模式 上一篇,对JavaScript函数进行了大体的介绍,这一篇对一些在工作中经常遇到的情况进行扩展. 在工作中,我们经常遇到很多需求,比如现在有一个需求: 一栋10层的大楼,当我们在坐电梯时,电 ...
- jQuery键盘控制方法,以及键值(keycode)对照表
键盘控制应用范围非常广泛,比如快捷键控制页面的滚动:在填写表单时候,限制输入内容:或者是屏蔽复制.粘贴.退后等功能.这里说说用jQuery怎么来实现.个人觉得jQuery比原生态的JS好用,代码简单清 ...
- Bootstrap_排版_文字样式
一.段落 段落是排版中另一个重要元素之一.在Bootstrap中为文本设置了一个全局的文本样式(这里所说的文本是指正文文本): 1.全局文本字号为14px(font-size). 2.行高为1.428 ...
- canvas新属性
lineCap默认值是butt,还有aquare,round 使用:context.lineCap="butt" lineJoin miter是默认 还可以是round,bevel ...
- 深入Java虚拟机读书笔记第一章Java体系结构介绍
第1章 Java体系结构介绍 Java技术核心:Java虚拟机 Java:安全(先天防bug的设计.内存).健壮.平台无关.网络无关(底层结构上,对象序列化和RMI为分布式系统中各个部分共享对象提供了 ...