这题主要考察观察能力。

2^63最多只需要开7次根号就会变成1,当数字变成1之后就不需要再对其进行操作。

对于含有大于1数字的区间,向下更新。

对于数字全为1的区间,直接返回。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath> #define LL long long int
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define lc rt << 1
#define rc rt << 1 | 1 using namespace std; const int MAXN = ; LL sum[MAXN << ];
bool one[MAXN << ]; void PushUp( int rt )
{
sum[rt] = sum[lc] + sum[rc];
one[rt] = one[lc] && one[rc];
return;
} void build( int l, int r, int rt )
{
if ( l == r )
{
scanf( "%I64d", &sum[rt] );
if ( sum[rt] <= ) one[rt] = true;
else one[rt] = false;
return;
}
int m = ( l + r ) >> ;
build(lson);
build(rson);
PushUp( rt );
return;
} void Update( int L, int R, int l, int r, int rt )
{
if ( one[rt] ) return;
if ( l == r )
{
sum[rt] = (LL)sqrt( (double)sum[rt] );
//之前这里忘了更新one,一直TLE
     if ( sum[rt] <= ) one[rt] = true;
else one[rt] = false;
return;
}
int m = ( l + r ) >> ;
if ( L <= m ) Update( L, R, lson );
if ( R > m ) Update( L, R, rson );
PushUp( rt );
return;
} LL Query( int L, int R, int l, int r, int rt )
{
   //这句不要,之前想错了
   //if ( one[rt] ) return (LL)r - l + 1;
if ( L <= l && r <= R ) return sum[rt]; int m = ( l + r ) >> ;
LL res = ;
if ( L <= m ) res += Query( L, R, lson );
if ( R > m ) res += Query( L, R, rson );
return res;
} int N; int main()
{
int cas = ;
while ( scanf( "%d", &N ) == )
{
build( , N, );
int Q;
scanf( "%d", &Q );
printf( "Case #%d:\n", ++cas );
while ( Q-- )
{
int op, a, b;
scanf( "%d%d%d", &op, &a, &b );
if ( b < a ) swap(a, b);
if ( op )
{
printf("%I64d\n", Query( a, b, , N, ) );
}
else
{
Update( a, b, , N, );
}
}
puts("");
}
return ;
}

HDU 4027 Can you answer these queries(线段树 + 观察 )的更多相关文章

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

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

  3. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

  4. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  5. HDU 4027 Can you answer these queries? (线段树成段更新 && 开根操作 && 规律)

    题意 : 给你N个数以及M个操作,操作分两类,第一种输入 "0 l r" 表示将区间[l,r]里的每个数都开根号.第二种输入"1 l r",表示查询区间[l,r ...

  6. hdu 4027 Can you answer these queries?

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

  7. HDU 4027 Can you answer these queries?(线段树区间开方)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  8. HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】

    Can you answer these queries? Time Limit:2000MS     Memory Limit:65768KB     64bit IO Format:%I64d & ...

  9. hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  10. HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)

    题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的 ...

随机推荐

  1. 第10章 新建工程-库函数版—零死角玩转STM32-F429系列

    第10章     新建工程—库函数版 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fire ...

  2. C# if语句

    一.C# if语句 if语句根据条件判断代码该执行哪一个分支. if语句有两个或两个以上的分支供代码选择,但是每次只能执行一个分支. 1. 基本if语句 语法格式如下: if(expression){ ...

  3. 阅读list

    最近感觉效率不高,其实有很多事情要做的,读书的速度也慢下来了,要抓紧时间的了. 继续读deep learning 一书的part II. 读完jifeng dai的几篇文章,去年欠下的债务啊.其中包括 ...

  4. 【学时总结】◆学时·VIII◆ 树形DP

    ◆学时·VIII◆ 树形DP DP像猴子一样爬上了树……QwQ ◇ 算法概述 基于树的模型,由于树上没有环,满足DP的无后效性,可以充分发挥其强大统计以及计算答案的能力. 一般来说树形DP的状态定义有 ...

  5. spring-mybatis整合项目 异常处理

    java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorIm ...

  6. js将人民币数字转大写

    function numberToUpper(money) { var cnNums = new Array("零", "壹", "贰", ...

  7. .NET 客户IP地址捕捉

    MVC模式下要获取客户IP可以在ActionFilterAttribute中进行拦截 filterContext.HttpContext.Request.UserHostAddress 同样,在Web ...

  8. POJ-3126 BFS,埃式筛选及黑科技

    题目大意:给定两个四位素数a  b,要求把a变换到b,变换的过程要保证  每次变换出来的数都是一个 四位素数,而且当前这步的变换所得的素数  与  前一步得到的素数  只能有一个位不同,而且每步得到的 ...

  9. 34-Cookie-based认证实现

    新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController.cs u ...

  10. wlr快捷键

    ref:http://www.cnblogs.com/zhangyang/archive/2011/07/22/2113856.html   Windows Live Writer提供了许多方便的快捷 ...