https://vjudge.net/contest/66989#problem/H

此题真是坑到爆!!说好的四舍五入害我改了一个多小时,不用四舍五入!!有好几个坑点,注意要交换l,r的位置,还有输出格式问题

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
const int maxn=;
ll value[maxn<<];
void pushup(int rt)//pushup应该随题目变化情况改变而改变
{
value[rt]=value[rt<<]+value[rt<<|];
}
void btree(int l,int r,int rt)
{
if(l==r)
{
scanf("%lld",&value[rt]);
return ;
}
int m=(l+r)>>;
btree(ls);
btree(rs);
pushup(rt);
}
void update(int L,int R,int l,int r,int rt)
{
if(value[rt]==r-l+)return;//没有这句就会超时
if(l==r)
{
value[rt]=(ll)(sqrt(value[rt]));//不四舍五入
return;
}
int m=(l+r)>>;
if(L<=m)update(L,R,ls);
if(R>m)update(L,R,rs);
pushup(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)return value[rt];
int m=(l+r)>>;
ll ans=;
if(L<=m)ans+=query(L,R,ls);
if(R>m)ans+=query(L,R,rs);
return ans;
}
int main()
{
int n,m,cnt=;
while(~scanf("%d",&n)){
printf("Case #%d:\n",++cnt);
btree(,n,);
scanf("%d",&m);
while(m--){
int t,l,r;
scanf("%d%d%d",&t,&l,&r);
if(l>r)swap(l,r);//这一点也是容易被坑的!!
if(t==)update(l,r,,n,);
if(t==)printf("%lld\n",query(l,r,,n,));
}
printf("\n");
}
return ;
}
/*
10
1 2 3 4 5 6 7 8 9 10
5
0 1 10
1 1 10
1 1 5
0 5 8
1 4 8
*/

hdu4027线段树的更多相关文章

  1. hdu-4027线段树练习

    title: hdu-4027线段树练习 date: 2018-10-10 18:07:11 tags: acm 算法 刷题 categories: ACM-线段树 # 概述 这道线段树的题可以说是我 ...

  2. HDU4027 线段树

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  3. HDU4027(线段树单点更新区间)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  4. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

  5. BZOJ3211花神游历各国-线段树&树状数组-(HDU4027同类型)

    (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 题意:BZOJ HDU  原题目描述在最下面.  两种操作,1:把区间的数字开方一次,2:区间求和. 思路: 线段树:  显然不能暴力 ...

  6. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

  7. hdu4027(线段树)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 线段树功能:区间修改,区间求和. 分析:因为每个数至多开6次平方就变1了,所以对于每一段全为1的 ...

  8. Can you answer these queries?(HDU4027+势能线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...

  9. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

随机推荐

  1. web从入门开始(5)-----表单

    1.   表单的概念 是用来获取客户端用户数据的(信息)的.如:注册表单,查询表单,登录表单等. 2.  表单的工作原理 1.浏览有表单的网页,填写一些必要的信息,然后单击某个按钮,进行提交. 2.这 ...

  2. 使用sudo提示用户不在sudoers文件中的解决方法

    切换到root用户 [linux@localhost ~]$ su root 密码: [root@localhost ~]# 2 查看/etc/sudoers文件权限,如果只读权限,修改为可写权限 [ ...

  3. Linux学习之Vim使用

    一 为何要学Vim 所有的Unix Like系统都有自带vi编辑器 一些软件的编辑接口会自动调起vi 作为vi的升级版,vim具有程序编辑功能,而且具有代码颜色高亮显示.辨别代码的正确性等功能 以上优 ...

  4. javascript中replace使用总结

    ECMAScript提供了replace()方法.这个方法接收两个参数,第一个参数可以是一个RegExp对象或者一个字符串,第二个参数可以是一个字符串或者一个函数.现在我们来详细讲解可能出现的几种情况 ...

  5. [SinGuLaRiTy] 平衡树

    [SinGuLaRiTy-1009] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 二叉查找树 二叉查找树是指具有下列性质的非空二叉树: ⑴ ...

  6. 测试开发Python培训:实现屌丝的黄色图片收藏愿望(小插曲)

    男学员在学习python的自动化过程中对于爬虫很感兴趣,有些学员就想能收藏一些情色图片,供自己欣赏.作为讲师只能是满足愿望,帮助大家实现对美的追求,http://wanimal.lofter.com/ ...

  7. thinkphp3.2.x多图上传并且生成多张缩略图

    html部分 <!DOCTYPE html><html><head><meta http-equiv="Content-Type" con ...

  8. 【Ubuntu】您没有查看“sf_VirtualDisk”的内容所需的权限。

    原文链接:http://www.crifan.com/can_not_access_share_folder_in_ubuntu_virtualbox/ [问题] 之前已经搞定可以自动共享文件夹了: ...

  9. Centos安装MySql、Java、Tomcat

    一.安装MySql 安装MySql yum install -y mysql-server mysql mysql-devel 启动MySql服务 service mysqld start 为root ...

  10. 使用SQL存储过程有什么好处 用视图有什么好处

    随便胡乱说几点,大家补充一下.1.预编译,已优化,效率较高.避免了SQL语句在网络中传输然后再解释的低效率.2.如果公司有专门的DBA,写存储过程可以他来做,程序员只要按他提供的接口调用就好了.这样分 ...