题目链接:点击打开链接

题意:

给定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. codeforces 13E . Holes 分块

    题目链接 nextt数组表示这个位置的下一个位置. cnt数组表示这个位置 i 到nextt[i]可以弹几次. end[i] 表示在从 i 弹出去的情况下, 最后一个位置是哪里. 然后就看代码吧. # ...

  2. python 文本编辑基础记录

    不熟悉编码方式,同时python的编码方式折磨我了很长时间,记录下,以免忘记,本文内容存在错误,是自己理解,看到仅当参考 Unicode 是字符集,有点像一本字典,utf-8是在unicode这本字典 ...

  3. c/c++:内存泄露和野指针的概念

    内存泄漏 用动态存储分配函数动态开辟的空间,在使用完毕后未释放,结果导致一直占据该内存单元.直到程序结束.即所谓内存泄漏.    注意:内存泄漏是指堆内存的泄漏. 简单的说就是申请了一块内存空间,使用 ...

  4. 【Linux指令】使用中学习(一)

    sed指令: 应用:对于大文件,比如10G的大文件,我遇到的是导出的数据库.sql文件,想要使用vim修改几乎是不可能的,用sed指令可以在不打开文件的情况下修改文件,下面是一些具体用法 删除文件特定 ...

  5. Windows 7 with SP1简体中文旗舰版(微软MSDN原版)+ 激活密钥

    在Windows 7六个版本中,旗舰版和企业版功能性能完全一样,同属诸版本之中的最高版本.现提供Windows 7 with SP1简体中文旗舰版(微软MSDN最新原版)+ 激活密钥如下: 32位版本 ...

  6. 压缩OLEVARIANT数据

    TCLIENTDATASET.DATA, TCLIENTDATASET.DELTA, TDATASETPROVIDER.DATA,它们的DATA属性的类型都是OLEVARIANT. 中间层和客户端之间 ...

  7. boost库在工作(40)串行通讯

    现代的计算机技术进步很快,各种的通讯也日新月异,像USB.网络.蓝牙.WIFI等通讯技术飞速地出现,改变了整个计算机的通讯能力,速度已经达到GBit级别.但是有一种最原始的通讯方式,还是保留了30年, ...

  8. Android切换页面效果的实现一:WebView+ViewFlipper

    前言: 这两周在帮学校做一个新生入学用的“新里程”的项目,要做到页面切换阅读的效果,自己百度了下,找到普遍是使用WebView+ViewFlipper的实现方法,但这种方法不能满足我的要求,因为它很难 ...

  9. html中文乱码

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">改成<m ...

  10. web前端学习之路

    test 随着自己对于web前端知识了解的越多,越来越发现自己真的好菜 一脸茫然阶段 两年前大学接触网页设计,那时对于网页设计一窍不通,只是看了一本自己大学编的一本入门教材,我甚至不知道那些网页设计的 ...