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 ...
随机推荐
- codevs 1689 搭建高塔
/*机智sort二维转一维*/ #include<iostream> #include<cstdio> #include<cstring> #include< ...
- FineUI开发实践-目录
点我订阅 目前所有博客的截图,方便离线观看,点图片 FineUI初学手册 下载,实例项目搭建 FineUI初学手册-部分JS整理 部分JS整理 ASP.NET-FineUI开发实践-1 实际开发环境是 ...
- Js 通过点击改变css样式
通过js 点击按钮去改变目标原始的背景颜色 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> ...
- [转]STL的内存分配器
题记:内存管理一直是C/C++程序的红灯区.关于内存管理的话题,大致有两类侧重点,一类是内存的正确使用,例如C++中new和delete应该成对出现,用RAII技巧管理内存资源,auto_ptr等方面 ...
- rhel安装eclipse
smb --> IDE --> 环境gcc(开发c) g++(开发c++)c++操作linux --> sqlite数据库linux平台自带sqlite数据库 基本SQL语言划分:D ...
- 【USACO 2.1.5】海明码
[题目描述] 给出 N,B 和 D,要求找出 N 个由0或1组成的编码(1 <= N <= 64),每个编码有 B 位(1 <= B <= 8),使得两两编码之间至少有 D 个 ...
- PHP Countable接口
实现该接口可以使用count()方法来获取集合的总数
- underscorejs-some学习
2.11 some 2.11.1 语法: _.some(list, predicate, [context]) 2.11.2 说明: 对list集合的每个成员根据predicate进行真值检测,如果一 ...
- mybatis 学习笔记(4) —— 批量新增数据
1.业务是从前台传入List<T> ,在controller层接受参数,并进行批量新增操作. 2.需要处理的细节 a) mybatis可以支持批量新增,注意数据表需要将主键设置成自增列. ...
- angularJS中如何写控制器
angularJS中的控制器是一个函数,用来向视图作用域中添加额外的功能,我们用它来给作用域对象设置初始状态,并添加自定义行为 当我们在页面上创建一个新的控制器时,angularJS会生成并传递一个新 ...