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 ...
随机推荐
- 数据层交换和高性能并发处理(开源ETL大数据治理工具--KETTLE使用及二次开发 )
ETL是什么?为什么要使用ETL?KETTLE是什么?为什么要学KETTLE? ETL是数据的抽取清洗转换加载的过程,是数据进入数据仓库进行大数据分析的载入过程,目前流行的数据进入仓库的 ...
- cocos2dx3.2 异步载入和动态载入
半个月没有更新博客,从这个项目開始学习了非常多细节的东西,都不太成系统.可是却是开发上线中必须经历的东西.比方超级玛丽系列(一)中的正确的异步载入,正确的分层.正确的合成和载入plist.及时的移除未 ...
- WPF的消息机制
前言 谈起“消息机制”这个词,我们都会想到Windows的消息机制,系统将键盘鼠标的行为包装成一个Windows Message,然后系统主动将这些Windows Message派发给特定的窗口,实际 ...
- Introduction to Probability (三) Independence
两个事件独立性的定义是:事件A的发生对事件B的发生毫无影响,即从A的发生与否.我们不能猜測出B是否发生. 从概率等式的表示来看就是B在A发生的情况下发生的概率等于B发生的概率本身. 进而引出了A与B同 ...
- 让工程师爱上CMMI,实现管理于无形 --- 中标软件CMMI L5之路 (1/2)
操作系统市场被微软等国外的IT厂商垄断的大环境下,中标软件作为市场夹缝中发展起来的民族企业,致力于成为中国操作系统旗舰企业.系列核心产品已经在政府.金融.教育.财税.公安.审计.交通.医疗.制造等行业 ...
- meminfo,df,
yx100:root@yxRouter:/# cat /proc/meminfoMemTotal: 126584 kBMemFree: 103156 kBBuffer ...
- [置顶] dubbo管理控制台安装
dubbo管理控制台开源部分主要包含:路由规则,动态配置,服务降级,访问控制,权重调整,负载均衡,等管理功能. 1.下载dubbo 地址:http://code.alibabatech.com/mvn ...
- Qt4在linux下的安装
1.下载SDK ftp://ftp.informatik.hu-berlin.de/pub/Mirrors/ftp.troll.no/QT/qtsdk/qt-sdk-linux-x86-opensou ...
- 【MongoDB】学习MongoDB推荐三本书
近期学习mongodb,感觉这三本书写得不错.非常大家分享一下:
- 《大数据互联网大规模数据挖掘与分布式处理》阅读笔记(四)-----WEB广告
作者: 沈慧 目前,许多WEB应用通过广告而维持生计,从在线广告中获益最多的是搜索应用,“adwords”模型就是一种用于搜索查询和广告匹配的模型.这一章介绍了在线广告的相关问题.在线算法.Adwor ...