hdu4027(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4027
线段树功能:区间修改,区间求和。
分析:因为每个数至多开6次平方就变1了,所以对于每一段全为1的线段做lazy标志,若该条线段全为1时,就不用继续往下update,修改复杂度O(6*N),查询O(logN)。
#pragma comment(linker,"/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#define LL long long
#define mod 1000000007
#define inf 0x3f3f3f3f
#define N 100010
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
LL sum[N<<],col[N<<],a[N];
void Pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
col[rt]=col[rt<<]&&col[rt<<|];
}
void build(int l,int r,int rt)
{
col[rt]=;
if(l==r)
{
sum[rt]=a[l];
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
Pushup(rt);
}
void update(int L,int R,int l,int r,int rt)
{
if(l==r)
{
sum[rt]=(LL)sqrt(sum[rt]);
if(sum[rt]==)col[rt]=;
return;
}
int m=(l+r)>>;
if(L<=m&&!col[rt<<])update(L,R,lson);
if(m<R&&!col[rt<<|])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)>>;
LL res=;
if(L<=m)res+=query(L,R,lson);
if(m<R)res+=query(L,R,rson);
return res;
}
int main()
{
int n,m,cas=;
while(scanf("%d",&n)>)
{
for(int i=;i<=n;i++)scanf("%I64d",&a[i]);
build(,n,);
scanf("%d",&m);
printf("Case #%d:\n",cas++);
while(m--)
{
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(x>y)swap(x,y);
if(op==)
{
update(x,y,,n,);
}
else
{
LL res=query(x,y,,n,);
printf("%I64d\n",res);
}
}
puts("");
}
}
hdu4027(线段树)的更多相关文章
- hdu-4027线段树练习
title: hdu-4027线段树练习 date: 2018-10-10 18:07:11 tags: acm 算法 刷题 categories: ACM-线段树 # 概述 这道线段树的题可以说是我 ...
- hdu4027线段树
https://vjudge.net/contest/66989#problem/H 此题真是坑到爆!!说好的四舍五入害我改了一个多小时,不用四舍五入!!有好几个坑点,注意要交换l,r的位置,还有输出 ...
- HDU4027 线段树
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- HDU4027(线段树单点更新区间)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- BZOJ3211花神游历各国-线段树&树状数组-(HDU4027同类型)
(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 题意:BZOJ HDU 原题目描述在最下面. 两种操作,1:把区间的数字开方一次,2:区间求和. 思路: 线段树: 显然不能暴力 ...
- HDU4027 Can you answer these queries? 线段树
思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...
- Can you answer these queries?(HDU4027+势能线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
随机推荐
- Oracle Patch Bundle Update
一.相关知识介绍 以前只知道有CPU(Critical Patch Update)和PSU(Patch Set Update),不知道还有个Bundle Patch,由于出现了TNS-12531的BU ...
- Kendo UI开发教程(20): Kendo MVVM 数据绑定(九) Text
Text绑定可以使用ViewModel来设置DOM元素的文本属性,如果需要设置input,textarea,或select的显示,需要使用value属性. 1 <span data-bind=& ...
- 解决SVG跨浏览器兼容性问题
Raphael JS:SVG/VML+JS实现跨浏览器的矢量图形实现方案 http://blog.csdn.net/tiewen/article/details/8535748 SVG那些小事儿 ht ...
- linux系统日志及其rsyslog服务
日志是系统用来记录系统运行时候的一些相关消息的纯文本文件 /var/log下保存着大量的纯文本日志文件 日志的目的是为了保持相关程序的运行状态,错误消息,为了对系统运行进行错误分析使用 1.内核消息 ...
- unity 调用android函数
unity 调用android函数 分类: unity2013-12-19 17:54 475人阅读 评论(0) 收藏 举报 unityandroidjar 我们知道,安卓project都有一个And ...
- 12306 Android客户端的libcheckcode.so解密及修复
源:http://blog.csdn.net/justfwd/article/details/45219895 这篇文章纯粹属于安全分析研究,请勿用于非法用途.如有侵犯到厂家,请告知作者删除 123 ...
- 眼见为实(2):介绍Windows的窗口、消息、子类化和超类化
眼见为实(2):介绍Windows的窗口.消息.子类化和超类化 这篇文章本来只是想介绍一下子类化和超类化这两个比较“生僻”的名词.为了叙述的完整性而讨论了Windows的窗口和消息,也简要讨论了进程和 ...
- Lucene.Net 2.3.1开发介绍 —— 二、分词(一)
原文:Lucene.Net 2.3.1开发介绍 -- 二.分词(一) Lucene.Net中,分词是核心库之一,当然,也可以将它独立出来.目前Lucene.Net的分词库很不完善,实际应用价值不高.唯 ...
- BZOJ 2096([Poi2010]Pilots-单调队列-差值)
2096: [Poi2010]Pilots Time Limit: 30 Sec Memory Limit: 162 MB Submit: 190 Solved: 97 [ Submit][ ...
- ERWin 7.1 和7.2 的官方FTP下载地址
ERWin 7.1 下载地址: ftp://ftp.ca.com/CAproducts/erwin/ServicePacks/AFEDM71sp2-b1303.exe ERWin 7.2 下载地址: ...