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 ...
随机推荐
- DataSet离线数据集实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- linux 进程数
一.linux系统支持的最大进程数 限制1:既然系统使用pid_t表示进程号,那么最大进程数不能超过pid_t类型的最大值吧 限制2:使用命令ulimit -u查看系统中限制的最大进程数,我的机器上是 ...
- .net截取指定长度汉字超出部分以指定的字符代替
下面是我在网上搜索,然后加以整理的关于在.net中截取指定长度汉字超出部分以指定的字符代替,来拓展一下自己的思路. 方法一 :在后台的select语句中直接操作或是在数据库中写一个存储过程 Selec ...
- #define和const的简单区别
面试常问:宏#define和const有什么区别? 1.编译器处理方式 define宏是在预处理阶段展开 const常量是在编译阶段使用 2.类型和安全检查不同 define宏没有类型,不做安全检查, ...
- html form <label>标签基础语法结构与使用案例教程(转载)
在表单布局中会遇到label标签的使用,label没有任何样式效果,有触发对应表单控件功能.比如我们点击单选按钮或多选框前文字对应选项就能被选中,这个就是对文字加了<label>标签实现. ...
- Spring4.0学习笔记(6) —— 通过工厂方法配置Bean
1.静态工厂方法: bean package com.spring.factory; public class Car { public Car(String brand) { this.brand ...
- 78 Subsets(求子集Medium)
题目意思:求解一个数组的所有子集,子集内的元素增序排列eg:[1,3,2] result:[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]思路:这是一个递推的过程 [] ...
- Css 描点
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- ucenter 通信原理
1.用户登录discuz,通过logging.php文件中的函数uc_user_login对post过来的数据进行验证,也就是对username和password进行验证. 2.如果验证成功,将调用位 ...
- SublimeText插件Anaconda如何关闭警告框
之前在学习python的时候,使用了代码编辑器Sublime Text 3并安装了强大的Anaconda插件.瞬间让Sublime Text3变身为Python的IDE. 在使用过程中,侧边栏的白点和 ...