hdu 4027(线段树)
题意:给定100000个数,两种操作,0 i j表示将i j这段的数字都开根号(向下取整),1 i j表示查询i j之间的所有值的和。。。(所有的和都不超过64位)
解题思路:这题要做区间的开平方操作,2^64最多可以做8次开平方操作,所以对于每个节点最多只有8次操作,这道题如果lazy思想的话就要保存每个区间被开平方的次数,但实际上好像不需要,只要一直找到叶子节点并将其开平方即可。如果整个区间内的数都为1,那么就直接返回即可,不需要再往下递归了。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef long long LL;
const int maxn = 100010;LL sum[maxn*4];
int n, m;void PushUp(int rt)
{sum[rt] = sum[rt<<1] + sum[rt<<1|1];return ;
}void build(int l, int r, int rt)
{sum[rt] = 0;if(l == r){scanf("%I64d", &sum[rt]);return ;}int m = (l+r)>>1;build(lson);build(rson);PushUp(rt);
}void update(int L, int R, int l, int r, int rt)
{if(l == r){sum[rt] = sqrt(1.0 * sum[rt]);return ;}if(L<=l && r<=R && sum[rt]==r-l+1) return ;int m = (l + r)>>1;if(L <= m) update(L, R, lson);if(m < R) update(L, R, rson);PushUp(rt);
}LL query(int L, int R, int l, int r, int rt)
{if(L <= l && r <= R)return sum[rt];int m = (l + r)>>1;LL ans = 0;if(L <= m) ans += query(L, R, lson);if(m < R) ans += query(L, R, rson);return ans;
}int main()
{int test = 0;while(scanf("%d", &n) != EOF){build(1, n, 1);int a, b, c;int x, y;scanf("%d", &m);printf("Case #%d:\n", ++test);while(m--){scanf("%d%d%d", &a, &b, &c);x = min(b, c);y = max(b, c);if(a == 0){update(x, y, 1, n, 1);}else{printf("%I64d\n", query(x, y, 1, n, 1));}}puts("");}return 0;
}
hdu 4027(线段树)相关推荐
- POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新
直接将这3题 放一起了 今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...
- hdu 5367(线段树+区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5367 官方题解: 对于求"高山脉"长度,可以利用线段树.树节点中保存左高度连续长度 ...
- hdu 5266(线段树+LCA)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5266 解题思路: 考虑dfs序,通过在简单的证明可知L~R的LCA为L ~R 中dfs序较小的那个位置 ...
- hdu 5124(线段树区间更新+lazy思想)
http://acm.hdu.edu.cn/showproblem.php?pid=5124 题意:区间覆盖次数问题. 解题思路:线段树水之. #include<iostream> #in ...
- HDU - 4578Transformation——线段树+区间加法修改+区间乘法修改+区间置数+区间和查询+区间平方和查询+区间立方和查询
[题目描述] HDU - 4578Transformation Problem Description Yuanfang is puzzled with the question below: The ...
- poj 2777 AND hdu 5316 线段树
区间染色问题,用线段树可以解决.颜色总类不多,故考虑用二进制数的每一位表示一种颜色,然后父节点的颜色就是孩子节点颜色"或"起来,加上lazy标记,轻松AC. poj 2777: 1 ...
- HDU 5238 线段树+数论
原题:http://acm.hdu.edu.cn/showproblem.php?pid=5238. 题解:给你长度为n的操作序列,和m组操作求每组操作的模29393的值.这道题直接显然是没有前途的, ...
- poj 2528 离散化+线段树 hdu 1698 线段树 线段树题目类型一:染色计数 外加离散化
第一次听到离散化是今年省赛的时候,一道矩形并的题,很水,就两个矩形... 今天再去做线段树已经发现离散化忘得差不多了...水逼的悲哀啊... 先看简单点的hdu 1698 http://acm.hdu ...
- HDU 1166(线段树)
线段树 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 #define N 200010 ...
- hdu 4417(线段树OR树状数组)
题意:输入一个长度为n的序列,然后m个询问,询问区间[a,b]中比h小的数的个数. 思路:树状数组或线段树离线处理. 树状数组1 View Code 1 #include<cstdio> ...
最新文章
- mysql开启binlog
- [转]计算机存在两个管理员,删除其中一个,administration隐藏显示
- Android ListViewview入门
- 《剑指offer》跳台阶
- 菜单之二:使用xml文件定义菜单
- SAP UI5 Fileupload control
- [svc]数字证书基础知识
- [Android]关于IntentService
- MailMail升级到1.0.2.4
- RPA机器人来了, 你的饭碗还好吗?
- CentOS下部署Hadoop高性能集群
- 提示获取硬盘分区失败,可能缺少硬盘驱动(ThinkStation使用U启动重装系统)
- Python 获取每月的工作日天数 (法定假+周末)天数
- 基于SSM的共享汽车管理系统设计与实现
- 关于JSP在Myeclipse里插入图片后浏览器显示不出来
- 搭建Longhorn
- JAVA_OPTS设置
- Python基础知识——字典:for循环遍历字典
- 数据模型 LP32 ILP32 LP64 ILP64 LLP64
- 如何配置Thymeleaf教程,及Thymeleaf的简单使用教程【一篇足够入门】
热门文章
- 中商惠民李超:500,000+ 便利店背后的精细化管理
- Java虚拟机运行流程
- 如何定位“Operating system error 32(failed to retrieve text for this error. Reason: 15105)”错误中被占用的文件...
- 工作区 暂存区 版本库之间的关系
- 基于SMB协议的共享文件读写 博客分类: Java
- OpenStack在线迁移
- 在Flash CS6中安装动画辅助制作插件DragonBones
- 在 asp.net mvc中的简单分页算法 (续)
- Git基础 1 ---- 版本控制系统的介绍
- 神经网络第五周tutorial解析