这题主要考察观察能力。

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. 永久免费开源的卫星地形图地图下载工具更新Somap2.13版本功能更新 更新时间2019年2月22日13:59:05

    一.下载地址 最新版本下载地址:SoMap2.13点击此处下载  二.系统自主开发特色功能展示 1.上百种地图随意下载 高德.百度.arcgis.谷歌.bing.海图.腾讯.Openstreet.天地 ...

  2. python中的zipfile

    zipfile - Work with ZIP archives ZipFile.namelist() Return a list of archive members by name. 返回压缩成员 ...

  3. SpringBoot学习12:springboot异常处理方式2(使用@ExceptionHandle注解)

    1.编写controller package com.bjsxt.controller; import org.springframework.stereotype.Controller; impor ...

  4. 微信小程序清除默认样式

    1.清除button的默认样式 button::after{border:none;}input{outline:none;border:none;list-style: none;}

  5. Latex 使用笔记,取消目录

    不使用标准模板(如ieee或者acm的模板)的前提下: \usepackage{hyperref} \hypersetup{bookmarks={false}} 或者 \usepackage[book ...

  6. ofbiz最新版13.07.01环境搭建、安装(linux环境下)

    一.软件必备: 1.jdk1.7 2.mysql5.6 3.安装tomcat 二.安装: 1.安装 JDK1.7 2.安装mysql数据库 3.下载apache-ofbiz-13.07.01.zip ...

  7. (一)、Python的简介与安装

    Python简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,作为ABC 语言的一种继承. ...

  8. pytorch中词向量生成的原理

    pytorch中的词向量的使用 在pytorch我们使用nn.embedding进行词嵌入的工作. 具体用法就是: import torch word_to_ix={'hello':0,'world' ...

  9. Pythony的数据类型和变量使用方法详解

    数据类型:计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定 ...

  10. 493. Reverse Pairs

    // see more at https://www.youtube.com/watch?v=j68OXAMlTM4 // https://leetcode.com/problems/reverse- ...