HDU4027 Can you answer these queries? 线段树
思路: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? 线段树的更多相关文章
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- 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 ...
- 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 ...
- 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 ...
- HDU-4027-Can you answer these queries?线段树+区间根号+剪枝
传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- hdu 4027 Can you answer these queries? 线段树
线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...
- HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)
题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...
- hdu4027Can you answer these queries?(线段树)
链接 算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记.查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新. 注意用——int64 注意L会大于R 这点我很纠结..您出题人故意 ...
随机推荐
- .NET高端职位招聘要求
系统架构师: 1.硕士及以上学历,博士有项目成果者优先: 2.五年以上工作经验,三年以上互联网经验,一年以上大型软件项目总体设计.分析.架构经验,有移动互联网或云计算虚拟化系统设计开发经验者优先: 3 ...
- 当在Win8下安装msi类型的文件出现errorcode 2503的解决方法
Win8安装程序出现2502.2503错误解决方法 在Win8中,在安装msi安装包的时候常常会出现代码为2502.2503的错误.其实这种错误是由于安装权限不足造成的,可以这种msi的安装包不像其他 ...
- SQL技术内幕一
范式:关系模型的规范化规则. Codd提出的三个数据库范式: 1. 第一范式 第一范式要求表中的每一行都是必须是唯一的.因为关系型数据库是基于集合论的,而集合的定义中,要求每一个元素都是唯一的(在关系 ...
- javascript操作html元素CSS属性
下面先记录一下JS控制CSS所使用的方法. 1.使用javascript更改某个css class的属性... <style type="text/css"> .ori ...
- python学习笔记——列表生成式与生成器
1.列表生成式(List Comprehensions) python中,列表生成式是用来创建列表的,相较于用循环实现更为简洁.举个例子,生成[1*1, 2*2, ... , 10*10],循环用三行 ...
- userInteractionEnabled
NO -------是自身View下面的按钮之类的能点 YES------是View自身的按钮能点击,他下面的不能点击
- sizeof()和strlen()在求字符串长度时的差别
sizeof()函数输出字符串长度时会把结束符计算在内: strlen()函数输出字符串长度时不会把结束符计算在内. 如图:
- MyEclipse使用自己的JDK和Tomcat
配置tomcat:window-->preferences-->myeclipse-->servers-->tomcat-->选一个-->右边选择一的tomcat的 ...
- 让Eclipse使用新版本的JRE
更新到新的 Mac OS X 再打开Eclipse 编译程序会报错, Exception in thread "main" java.lang.UnsupportedClassVe ...
- MongoDB服务器启动异常 1067
删掉mongod.lock文件就重启就可以了.