题目链接:点击打开链接

题意:

给定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 水线段树的更多相关文章

  1. 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 ...

  2. 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 ...

  3. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  4. Can you answer these queries? HDU 4027 线段树

    Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...

  5. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  6. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

  7. hdu4027Can you answer these queries?【线段树】

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  8. 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 ...

  9. V - Can you answer these queries? HDU - 4027 线段树 暴力

    V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...

随机推荐

  1. 轮播图插件myFocus使用

    myFocus官网下载源码,本文是v2.0.1版,解压后如下 将js包内文件拷入工程 在工程内引入 <script src="js/myfocus-2.0.1.min.js" ...

  2. sar

    雷达卫星数据产品介绍(一) — ERS 卫星 ERS-1 ERS-2 欧空局分别于 1991 年和 1995 年发射. 携带有多种有效载荷, 包括 侧视合成孔径雷达(SAR)和风向散射计等装置),由于 ...

  3. poj1651 最优矩阵乘法动态规划解题

    题目描述: 有若干个矩阵{Ai},元素都为整数且已知矩阵大小. 如果要计算所有矩阵的乘积A1 * A2 * A3 .. Am,最少要多少次整数乘法? 输入 第一行一个整数n(n <= 100), ...

  4. paip.提升用户体验---论文本编辑器的色彩方案

    paip.提升用户体验---论文本编辑器的色彩方案 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.ne ...

  5. [poj 2978]Colored Stones[状态压缩DP]

    题意: 给出n个石子,一共m种颜色.问最少去掉几个石子使得同种颜色全连续. 思路见注释. #include <algorithm> #include <cstdio> #inc ...

  6. ExecuteScalar

    ExecuteScalar运行查询,并返回查询所返回的结果集中第一行的第一列或空引用(假设结果集为空).忽略其它列或行. 使用 ExecuteScalar 方法从数据库中检索单个值. 由于不用创建行集 ...

  7. Foundation 学习

    官网 Foundation是个跟bootstrap齐名的前端框架. 移动优先,响应式,最低支持IE8. html+css+jq构建 网格Grid Basic: .row父容器 子元素类.column  ...

  8. English - because of,due to ,thanks to ,owing to ,as a result of ,on account of解析

    because of,due to ,thanks to ,owing to ,as a result of ,on account of 等都可以用来表示原因,但其用法却各有不同.下面就其用法分述如 ...

  9. Convert Binary Search Tree (BST) to Sorted Doubly-Linked List

    (http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html) Convert a BST to a sorted circu ...

  10. Spring学习之Jar包功能介绍(转)

    spring.jar 是包含有完整发布模块的单个jar 包.但是不包括mock.jar, aspects.jar, spring-portlet.jar, and spring-hibernate2. ...