题目链接

有n个数:当操作为1时求L到R的和;

当操作为0时更新L到R为原来的平方根;

不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底。、

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#define INF 0xfffffff
#define N 100010
using namespace std; #define Lson r<<1
#define Rson r<<1|1 struct SegTree
{
int L, R;
long long sum;
int mid()
{
return (L+R)>>;
}
int len()
{
return R-L+;
}
}a[N*]; void Update(int r, int L, int R)
{
if(a[r].len()==a[r].sum)
return ;
if(a[r].L == a[r].R)//到达叶子节点;
{
a[r].sum = (long long)sqrt(a[r].sum);
return ;
}
if(R<=a[r].mid())
Update(Lson, L, R);
else if(L > a[r].mid())
Update(Rson, L, R);
else
{
Update(Lson, L, a[r].mid());
Update(Rson, a[r].mid()+, R);
}
a[r].sum = a[Rson].sum + a[Lson].sum;
} void BuildSegTree(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
if(L == R)
{
scanf("%I64d", &a[r].sum);
return;
}
BuildSegTree(Lson, L, a[r].mid());
BuildSegTree(Rson, a[r].mid()+, R); a[r].sum = a[Rson].sum + a[Lson].sum;
}
long long Query(int r, int L, int R)
{
if(a[r].L == L && a[r].R == R)
{
return a[r].sum;
}
if(L>a[r].mid())
return Query(Rson, L ,R);
else if(R <= a[r].mid())
return Query(Lson, L, R);
else
{
long long ans1 = Query(Lson, L, a[r].mid());
long long ans2 = Query(Rson, a[r].mid()+, R);
return ans1 + ans2;
}
}
int main()
{
int n, m, L, R, op, t=;
while(scanf("%d", &n) != EOF)
{
BuildSegTree(, , n);
scanf("%d", &m);
printf("Case #%d:\n", t++);
while(m--)
{
scanf("%d%d%d", &op, &L, &R);
if(L>R)swap(L, R);//L和R的大小没说;
if(op==)
Update(, L, R);
else
{
long long ans=Query(, L, R);
printf("%I64d\n", ans);
}
}
printf("\n");
}
return ;
}

Can you answer these queries?---hdu4027的更多相关文章

  1. (线段树 区间查询更新) Can you answer these queries? -- hdu--4027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...

  2. Can you answer these queries?-HDU4027 区间开方

    题意: 给你n个数,两个操作,0为区间开方,1为区间求和 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 思路: 如果当该区间的数都为1,我们没必要 ...

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

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

  4. 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 ...

  5. kuangbin专题七 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 ...

  6. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  7. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

  8. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  9. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

随机推荐

  1. javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed

    1.使用HttpClient4.3 调用https出现如下错误: javax.net.ssl.SSLHandshakeException: sun.security.validator.Validat ...

  2. Django SimpleCMDB 使用序列化

    如下,前面我们是使用 urllib 方法来转换并传递数据的: [root@localhost ~]$ tail /data/script/getHostInfo.py if __name__ == ' ...

  3. Mybatis输入输出映射

    一.输入映射 1.传递简单类型 <select id="findUserById" parameterType="int" resultType=&quo ...

  4. Jquery-无法有效获取当前窗口高度

    今天碰到个很奇怪的事情,那就是滚动条往下滚动时候没有触发提示,反而是往上滚动的时候,触发了提示.百思不得其解,尤其是拿了美工大大的切图过来,一点问题都没有. 那么就进行console.log输出查看了 ...

  5. PowerDesigner快捷键【转】

    一般快捷键 快捷键 说明 F4 打开检查模型窗口,检查模型 F5 如果图窗口内的图改变过大小,恢复为原有大小即正常大小 F6 放大图窗口内的图 F7 缩小图窗口内的图 F8 在图窗口内中查看全部图内容 ...

  6. PowerDesigner 同步Name到Comment 及 同步 Comment 到Name

    PowerDesigner中使用方法为:     PowerDesigner->Tools->Execute Commands->Edit/Run Scripts 代码一:将Name ...

  7. git 命令自动补全

    下载 Git 的源代码 使用如下命令即可下载: git clone https://github.com/git/git 复制 git-completion.bash 源代码下有个 contrib/c ...

  8. 编译内核时出现__bad_udelay错误

    今天编译内核时候遇到了__bad_udelay错误,然后编不过去了,仔细一看发现是udelay函数的参数太大,内核不允许延时这么多.于是换成了mdelay函数,以毫秒为单位延时,问题解决.

  9. sencha touch Container tpl 监听组件插件(2013-9-14)

    将http://www.cnblogs.com/mlzs/p/3279162.html中的功能插件化 插件代码: /* *tpl模版加入按钮 *<div class="x-button ...

  10. git--指定不上传的文件夹

    在使用 vue-cli 脚手架的时候,有一个依赖模板文件夹是不希望被上传到git上的,因为里面文件太多了. 解决办法:手动创建git忽略push清单,node_module以及自身 1.文件夹内右键g ...