思路: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. PHP 各种函数

    usleep() 函数延迟代码执行若干微秒. unpack() 函数从二进制字符串对数据进行解包. uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID. time_sleep_unti ...

  2. Python3 面向对象

    Class 在Python中,定义类是通过class关键字: class Student(object): pass class后面紧接着是类名,即Student,类名通常是大写开头的单词,紧接着是( ...

  3. mysql用户管理,权限管理

    mysql权限 相关操作: 授予的权限分为四组: 列权限:和表中的一个具体列相关,例如:使用update 语句更新test表中name 列的值 表权限:和一个具体的表的所有数据相关,例如:使用 sel ...

  4. iOS之内存管理浅谈

    1.何为ARC ARC是automatic reference counting自动引用计数,在程序编译时自动加入retain/release.在对象被创建时retain count+1,在对象被re ...

  5. linux(centos)搭建svn

    1.yum install subversion 2.输入rpm -ql subversion查看安装位置 输入 svn --help可以查看svn的使用方法 3.创建svn版本库目录 mkdir - ...

  6. 使用Github总结

    1. 使用Git GUI 首先熟悉一下GUI,如下: 第一步,首先将代码fork到自己的版本库下面,如下: 并获取clone URL,如下图: 然后点击GUI克隆已有版本库,如下图: 点击克隆就可以得 ...

  7. Python 多进程

    import threading from time import sleep from msalt_proxy.client import Client def f(t): print t cli= ...

  8. linux系统管理

    系统 # uname -a               # 查看内核/操作系统/CPU信息# head -n 1 /etc/issue   # 查看操作系统版本# cat /proc/cpuinfo  ...

  9. MapReduce多表连接

    多表关联 多表关联和单表关联类似,它也是通过对原始数据进行一定的处理,从其中挖掘出关心的信息.下面进入这个实例. 1 实例描述 输入是两个文件,一个代表工厂表,包含工厂名列和地址编号列:另一个代表地址 ...

  10. jquery方法的参数解读

    18:22 2013/9/21 attr(name|properties|key,value|fn) 概述 设置或返回被选元素的属性值. 在jquery中[]表示可选参数,你可以不选,| 表示参数可以 ...