思路:http://www.cnblogs.com/gufeiyang/p/4182565.html

写写线段树

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+;
LL a[N<<];
void build(int rt,int l,int r){
if(l==r){
scanf("%I64d",&a[rt]);
return;
}
int m=(l+r)>>;
build(rt<<,l,m);
build(rt<<|,m+,r);
a[rt]=a[rt<<]+a[rt<<|];
}
void modify(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y){
if(a[rt]==r-l+)return;
}
if(l==r){
a[rt]=sqrt(1.0*a[rt]);
return;
}
int m=(l+r)>>;
if(x<=m)modify(rt<<,l,m,x,y);
if(y>m)modify(rt<<|,m+,r,x,y);
a[rt]=a[rt<<]+a[rt<<|];
}
LL ask(int rt,int l,int r,int x,int y){
if(x<=l&&r<=y)return a[rt];
LL ans=;
int m=(l+r)>>;
if(x<=m)ans+=ask(rt<<,l,m,x,y);
if(y>m)ans+=ask(rt<<|,m+,r,x,y);
return ans;
}
int main(){
int n,cas=;
while(~scanf("%d",&n)){
printf("Case #%d:\n",++cas);
build(,,n);
int q;
scanf("%d",&q);
while(q--){
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if(x>y)swap(x,y);
if(op)printf("%I64d\n",ask(,,n,x,y));
else modify(,,n,x,y);
}
printf("\n");
}
return ;
}

HDU4027 Can you answer these queries? 线段树的更多相关文章

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

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

  2. HDU4027 Can you answer these queries?(线段树 单点修改)

    A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...

  3. HDU 4027 Can you answer these queries? (线段树区间修改查询)

    描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to u ...

  4. hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和

    Can you answer these queries? Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  5. HDU-4027-Can you answer these queries?线段树+区间根号+剪枝

    传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...

  6. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  7. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  8. HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)

    题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...

  9. hdu4027Can you answer these queries?(线段树)

    链接 算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记.查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新. 注意用——int64 注意L会大于R 这点我很纠结..您出题人故意 ...

随机推荐

  1. 关于NPC和NP-Hard问题

    参考链接: 1. P.NP.NPC和NP-hard问题的理解 参考:<算法导论>

  2. JS拖拽原理

    实现拖拽效果主要跟鼠标的三个事件有关: onmousedown : 选择要拖拽的元素 onmousemove : 移动元素 onmouseup : 释放元素 三个事件的关系: obj.onmoused ...

  3. C# 实体model验证输出

    新建Model实体: [Required(ErrorMessage = @"地址 1 为必填项!")] [StringLength(, ErrorMessage = @" ...

  4. Yii表单模型使用及以数组形式提交表单数据

    按Yii文档里的描述,Yii在处理表单的一般过程是: 创建表单对应的模型类,设置字段验证规则 创建表单提交对应的action,处理提交的内容 在视图中创建表单form 在刚刚的一个小项目里,想使用aj ...

  5. windows 下 scrapy的安装

    安装参考博客:http://davenzhang.com/scrapy_install.htm 我是先安装了scrapy,发现import scrapy 的时候报错.之后一次安装了下面关联软件的.ex ...

  6. map遍历的三种基础用法

    java中遍历MAP的几种方法 Java代码 Map<String,String> map=new HashMap<String,String>();    map.put(& ...

  7. easy-ui datagrid

    Easy-ui引用    <link href="css/EasyUI/themes/icon.css" rel="stylesheet" type=&q ...

  8. HTTP - PUT 上传文件/Shell (二)

    上一篇文章 HTTP - PUT 上传文件/Shell 讲到自己搭了一个环境,去测试HTTP - PUT上传Shell.最近又遇到几个PUT上传的例子,也成功上传了几次,来分享一下思密达. 0x00 ...

  9. python @property 属性

    在绑定属性时,如果我们直接把属性暴露出去,显然不合适,是通过getter和setter方法来实现的,还可以定义只读属性,只定义getter方法,不定义setter方法就是一个只读属性: class P ...

  10. ruby的gem和boundle安装解决办法

    gem和boundle安装在国内被墙,淘宝提供了淘宝提供了RubyGems的国内镜像站点,解决办法是: 对于gem: $ gem sources --remove https://rubygems.o ...