思路: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. C++字符串函数与C字符串函数比较

    赋值拷贝: #include <iostream> #include <string> using namespace std; void main(){ string a=& ...

  2. form表单重置

    Jquery中重置表单的错误姿势 $('#yigeform').reset() 正确姿势 $('#yigeform')[0].reset()

  3. lnmp 虚拟主机配置及重写

    lnmp安装与调试,请看 http://www.cnblogs.com/lin3615/p/4376224.html 虚拟主机的配置编辑nginx配置文件 nginx.conf此为主配置文件 vim ...

  4. JavaScript 判断用户输入的邮箱及手机格式是否正确

    JavaScript判断用户输入的邮箱格式是否正确.判断用户输入的手机号格式是否正确,下面有个不错的示例,感兴趣的朋友可以参考下. 复制代码代码如下: /*  * 功能:判断用户输入的邮箱格式是否正确 ...

  5. php获取汉字首字母的函数

    本文介绍用php实现汉字转化为首字母的方法,主要功能是:功能明确,易于修改维护和扩展: 英文的字串:不变返回(包括数字):中文字符串:返回拼音首字符: 中英混合串: 返回拼音首字符和英文. 网上的方法 ...

  6. PHP学习心得(十)——控制结构

    if 结构是很多语言包括 PHP 在内最重要的特性之一,它允许按照条件执行代码片段. if 语句可以无限层地嵌套在其它 if 语句中,这给程序的不同部分的条件执行提供了充分的弹性. else 延伸了  ...

  7. Python OptionParser学习

    from optparse import OptionParser import sys def main(): p = OptionParser() p.add_option('-n','--nam ...

  8. Hadoop学习—最大的敌人是自己

    (大讲台:国内首个it在线教育混合式自适应学习) 如果没有那次学习机会,我依然深陷在封闭的泥塘里. 我是今年刚毕业的大学生,我学习成绩不错,所学也是国内很厉害的专业,全国范围内只有6所院校拥有学位授予 ...

  9. jquery方法的参数解读

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

  10. Hanoi

    递归解决 汉诺塔 class Han{ int num; int steps; Han(int num){ this.num=num; } void total() { System.out.prin ...