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 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
随机推荐
- Android Studio 添加Assets目录
Android Studio 添加Assets目录: 法一: Since Android Studio uses the new Gradle-based build system, you shou ...
- charset
<meta charset="UTF-8" /> 这是html5的写法. <meta http-equiv=“content-type” content=“tex ...
- Linux主要发行版本介绍
Linux主要发行版本介绍 1.Red Hat Linux Red Hat是一个比较成熟的Linux版本,无论在销售还是装机量上都比较可观.该版本从4.0开始同时支持Intel.Alpha及Sparc ...
- 分析Ext2文件系统结构。
1. 目的 分析Ext2文件系统结构. 使用 debugfs 应该跟容易分析 Ext2文件系统结构 了解ext2的hole的 2. 准备工作 预习文件系统基本知识: http://www.doc88. ...
- favicon
<link rel="icon" href="Images/wangyi.ico" type="text/plain" />
- 4.跟我学solr---SolrRequestHandler具体解释
概述 我们在使用solr admin在做查询的时候,能够看到Request-Hander(qt)输入栏中有"/select"这样一个uri.当我们点击查询的时候所发起的请求是这种. ...
- 赵雅智_BroadcastReceiver
BroadcastReceiver 用于接收程序(包含用户开放的程序和系统内建程序)所发出的Broadcast intent 耗电量 开机启动 窃取别人短信 窃取别人电话 开发: 创建须要启动的Br ...
- android 回调
调函数(callback Function),顾名思义,用于回调的函数. 回调函数只是一个功能片段,由用户按照回调函数调用约定来实现的一个函数.回调函数是一个工作流的一部分,由工作流来决定函数的调用 ...
- SQL 常用基础语句
1.SQL SELECT 语句 语法:SELECT 列名称 FROM 表名称 2.SQL SELECT DISTINCT 语句 语法:SELECT DISTINCT 列名 ...
- MFC数据类型(data types)
为便于理解MFC库函数中的各种形参,现将MFC中常见的参数类型总结如下: 下面这些是和Win32程序(SDK程序)共同使用的数据类型: 数据类型 意义 BOOL Boolean值(布尔值,不是TRUE ...