Spoj 2713 Can you answer these queries IV 水线段树
题目链接:点击打开链接
题意:
给定n长的序列
以下2个操作
0 x y 给[x,y]区间每一个数都 sqrt
1 x y 问[x, y] 区间和
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <math.h>
#include <vector>
#include <set>
using namespace std;
#define ll long long
#define N 100005
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
#define Num(x) tree[x].num
#define Sum(x) tree[x].sum
inline int Mid(int x, int y){return (x+y)>>1;}
struct Subtree{
int l, r;
ll num, sum;
}tree[N<<2];
ll a[N];
void push_up(int id){
if(L(id) == R(id))return;
Sum(id) = Sum(Lson(id)) + Sum(Rson(id));
if(Num(Lson(id)) <= 1 && Num(Rson(id)) <= 1)
Num(id) = 1;
else Num(id) = 2;
}
void build(int l, int r, int id){
L(id) = l; R(id) = r;
if(l == r) { Num(id) = Sum(id) = a[l]; return ;}
int mid = Mid(l, r);
build(l, mid, Lson(id));
build(mid+1, r, Rson(id));
push_up(id);
}
void updata(int l, int r, int id){
if(L(id) == R(id))
{
Sum(id) = Num(id) = (ll)sqrt((double)Sum(id));
return ;
}
if(l == L(id) && R(id) == r && Num(id) <= 1) return ; int mid = Mid(L(id), R(id));
if(mid < l)
updata(l, r, Rson(id));
else if(r <= mid)
updata(l, r, Lson(id));
else {
updata(l, mid, Lson(id));
updata(mid+1, r, Rson(id));
}
push_up(id);
}
ll query(int l, int r, int id){
if(l == L(id) && R(id) == r)
return Sum(id);
int mid = Mid(L(id), R(id));
if(mid < l)
return query(l, r, Rson(id));
else if(r <= mid)
return query(l, r, Lson(id));
else return query(l, mid, Lson(id)) + query(mid+1, r, Rson(id));
}
int n;
void solve(){
int q, op, x, y;
for(int i = 1; i <= n; i++)scanf("%lld", &a[i]);
build(1, n, 1);
scanf("%d",&q);
while(q--){
scanf("%d %d %d", &op, &x, &y);
if(x > y) swap(x, y);
if(op == 0)
updata(x, y, 1);
else
printf("%lld\n", query(x, y, 1));
}
}
int main(){
int Cas = 1;
while(~scanf("%d", &n)){
printf("Case #%d:\n", Cas++);
solve();
puts("");
}
return 0;
}
Spoj 2713 Can you answer these queries IV 水线段树的更多相关文章
- spoj gss2 : Can you answer these queries II 离线&&线段树
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...
- 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 ...
- GSS4 - Can you answer these queries IV(线段树懒操作)
GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...
- Can you answer these queries? HDU 4027 线段树
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...
- GSS4 2713. Can you answer these queries IV 线段树
GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- hdu4027Can you answer these queries?【线段树】
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- Can you answer these queries III(线段树)
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...
- V - Can you answer these queries? HDU - 4027 线段树 暴力
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
随机推荐
- sass教程
sass教程 1. 使用变量; sass让人们受益的一个重要特性就是它为css引入了变量.你可以把反复使用的css属性值 定义成变量,然后通过变量名来引用它们,而无需重复书写这一属性值.或者,对于仅使 ...
- js创建对象的几种常用方式小结
第一种模式:工厂方式 var lev=function(){ return "666"; }; function Parent(){ var Child = new Object ...
- IP校验和
#include <stdio.h> #include <unistd.h> #include <linux/if_ether.h> #include <li ...
- android中获取root权限的方法以及原理(转)
一. 概述 本文介绍了android中获取root权限的方法以及原理,让大家对android 玩家中常说的“越狱”有一个更深层次的认识. 二. Root 的介绍 1. Root 的目的 可以让我们拥有 ...
- centos 6.7 perl 版本 This is perl 5, version 22 安装DBI DBD
<pre name="code" class="cpp">centos 6.7 perl 版本 This is perl 5, version 22 ...
- poj1563---蜗牛爬井
#include <stdio.h> #include <stdlib.h> int main() { int dayTh; float Udis,currentHeight, ...
- 《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova
感谢朋友支持本博客,欢迎共同探讨交流,因为能力和时间有限,错误之处在所难免,欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地 ...
- IE 11 无法访问某些不兼容性视图的解决方法
今天下午部署公司的项目时,用IE 11只能加载到JSP页面的静态元素,其中下拉文本框的信息获取不到, 后来,发现是IE 11不兼容的原因,于是,在菜单条“工具”——“兼容性视图设置”,将不兼容页面的网 ...
- HDU OJ 5317 RGCDQ( 2015多校联合训练第3场) 暴力打表+小技巧
题目连接:Click here 题意:在一个[L,R]内找到最大的gcd(f[i],f[j])其中L<=i<j<=R,f[x]表示i分解质因数后因子的种类数.eg:f[10]=2(1 ...
- csapp lab2 bomb 二进制炸弹《深入理解计算机系统》
bomb炸弹实验 首先对bomb这个文件进行反汇编,得到一个1000+的汇编程序,看的头大. phase_1: 0000000000400ef0 <phase_1>: 400ef0: 48 ...