这题主要考察观察能力。

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. 剑指offer40

    class Solution { public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { ) ret ...

  2. linq 和lambda查询

    EF 查询的两种 写法. linq 方法 或者 lambda方法 其中 ,只有tolist()的时候,才会真正的 在数据库中执行. 如果没有 tolist 方法,那么province1是 iqueab ...

  3. django2.2连接mysql遇到的坑

    1.mysql数据库配置 2.首先需要建一个myweb数据库 3.执行数据库迁移命令makemigrations python manage.py makemigrations MySite 报错: ...

  4. 第48章 MDK的编译过程及文件类型全解—零死角玩转STM32-F429系列

    第48章     MDK的编译过程及文件类型全解 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.co ...

  5. Ecliplse 重命名后web.xml 报错Attribute "xmlns" was already specified for element "web-app".

      报错信息:Attribute "xmlns" was already specified for element "web-app" 由于项目的重命名,出现 ...

  6. Python——配置环境的导出与导入

    导出Python环境安装包[root@bogon ~]# pip freeze > packages.txt 这将会创建一个 packages.txt文件,其中包含了当前环境中所有包及各自的版本 ...

  7. vue的生命周期和路由守卫

    组件相关钩子函数: beforeCreate.created.beforeMount.mounted.beforeUpdate.updated.beforeDestroy.destoryed   还有 ...

  8. lintcode_69_二叉树的层次遍历

    二叉树的层次遍历   描述 笔记 数据 评测 给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问) 您在真实的面试中是否遇到过这个题? Yes 哪家公司问你的这个题? LinkedIn Airb ...

  9. lintcode_93_平衡二叉树

    平衡二叉树   描述 笔记 数据 评测 给定一个二叉树,确定它是高度平衡的.对于这个问题,一棵高度平衡的二叉树的定义是:一棵二叉树中每个节点的两个子树的深度相差不会超过1. 您在真实的面试中是否遇到过 ...

  10. python导包语句执行

    今天在做项目中遇到一个问题,在first_page中引用login的登录方法,第一次执行登录可以正常登录,登录成功后,再选择返回主菜单,回到上个页面,再选择登录时报错“login_class isno ...