链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4027

分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底。、
注意:给的X Y大小未知,会出现X > Y的情况

代码:

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
const int N = ;
using namespace std; #define Lson r<<1
#define Rson r<<1|1
#define mid a[r].Mid() struct node
{
int L, R;
long long sum;
int Mid()
{
return (L+R)>>;
}
int len()
{
return (R-L+);
};
} a[N<<]; void BuildTree(int r, int L, int R)
{
a[r].L=L, a[r].R=R; if(L==R)
{
scanf("%lld", &a[r].sum);
return ;
} BuildTree(Lson, L, mid);
BuildTree(Rson, mid+, R); a[r].sum = a[Lson].sum + a[Rson].sum;
} void Oper(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*1.0);
return ;
} if(R<=mid)
Oper(Lson, L, R);
else if(L>mid)
Oper(Rson, L, R);
else
{
Oper(Lson, L, mid);
Oper(Rson, mid+, R);
} a[r].sum = a[Lson].sum + a[Rson].sum;
} long long Query(int r, int L, int R)
{
if(a[r].L==L && a[r].R==R)
return a[r].sum; if(R<=mid)
return Query(Lson, L, R);
else if(L>mid)
return Query(Rson, L, R);
else
{
return Query(Lson, L, mid) + Query(Rson, mid+, R);
}
} int main()
{
int n, m, t=;
while(scanf("%d", &n)!=EOF)
{ BuildTree(, , n); int L, R, e; scanf("%d", &m); printf("Case #%d:\n", t++);
while(m--)
{
scanf("%d%d%d", &e, &L, &R); if(L>R)
swap(L, R);
if(e==)
Oper(, L, R);
else
{
printf("%lld\n", Query(, L, R));
}
} printf("\n");
}
return ;
}

(线段树 区间查询更新) Can you answer these queries? -- hdu--4027的更多相关文章

  1. V - Can you answer these queries? HDU - 4027 线段树 暴力

    V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...

  2. Can you answer these queries? HDU 4027 线段树

    Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...

  3. 【DFS序+线段树区间更新区间求最值】HDU 5692 Snacks

    http://acm.hdu.edu.cn/showproblem.php?pid=5692 [思路] 每更新一个点,子树的所有结点都要更新,所以是区间更新 每查询一个点,子树的所有结点都要查询,所以 ...

  4. Can you answer these queries? HDU - 4027 (线段树,区间开平方,区间求和)

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

  5. 线段树 SP1716 GSS3 - Can you answer these queries III

    SP1716 GSS3 - Can you answer these queries III 题意翻译 n 个数,q 次操作 操作0 x y把A_xAx 修改为yy 操作1 l r询问区间[l, r] ...

  6. 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国

    SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...

  7. 线段树 SP1043 GSS1 - Can you answer these queries I

    SP1043 GSS1 - Can you answer these queries I 题目描述 给出了序列A[1],A[2],-,A[N]. (a[i]≤15007,1≤N≤50000).查询定义 ...

  8. Can you answer these queries? HDU - 4027(线段树+技巧)

    题意:给一个数组序列, 数组长度为100000 两种操作: 一种操作是将某一个固定区间所有数开方(向下取整) 另一种操作是询问某个区间的所有数字之和. 由于数不超过263,因此开个七八次就变成1,由于 ...

  9. Can you answer these queries? HDU - 4027 有点坑

    #include<iostream> #include<cstring> #include<cstdio> #include<math.h> #incl ...

随机推荐

  1. MongoDB 数据查询

    数据查询 基本查询 方法find():查询 db.集合名称.find({条件文档}) 方法findOne():查询,只返回第一个 db.集合名称.findOne({条件文档}) 方法pretty(): ...

  2. break、continue、pass介绍

    break.continue.pass介绍 break:跳出当前循环 continue:跳出本次循环,进行下一次循环 pass:什么也不做,占位.

  3. oracle系统视图字段说明

    oracle系统表v$session.v$sql表的列字段说明‍ 在本视图中,每一个连接到数据库实例中的 session都拥有一条记录.包括用户 session及后台进程如 DBWR, LGWR, a ...

  4. sql重复数据只取一条记录

    1.SQL SELECT DISTINCT 语句 在表中,可能会包含重复值.这并不成问题,不过,仅仅列出不同(distinct)的值. 关键词 DISTINCT 用于返回唯一不同的值. 语法: SEL ...

  5. xpath定位--绝对与相对的定位

    xpath定位--绝对与相对的定位: xpath定位即为xml路径语言,它是一种用来确定xml文档中某部分位置的语言,xpath基于xml的树状结构,提供在数据结构中找寻节点的能力 xpath的相对定 ...

  6. .net 委托的用法

    定义了两个委托 //Func有返回值:Action无返回值.两个委托 Func<int,int> f= a =>a+1;//参数,返回值: int reslut=f(5);//6

  7. 10.9zuoye

    public class fulei { public fulei() { System.out.println("欢迎使用海尔"); } public String Pinpai ...

  8. tf.unstack\tf.unstack

    tf.unstack 原型: unstack( value, num=None, axis=0, name='unstack' ) 官方解释:https://tensorflow.google.cn/ ...

  9. 如何学习mybatis

    最近几天学习了mybatis框架,我是mybatis视频学习的.看这篇文章,我建议首先要会熟练使用MVC架构,再学习这个框架. 在我们写传统的MVC模式写Bean,Dao,Servlet时,我们每次调 ...

  10. spotlight

    spotlight - 必应词典 美['spɑt.laɪt]英['spɒt.laɪt] n.聚光灯:聚光灯照亮的地方:聚光灯照明圈:媒体和公众的注意 v.用聚光灯照:突出报道(以使公众注意) 网络射灯 ...