传送门Can you answer these queries?

题意:线段树,只是区间修改变成 把每个点的值开根号;

思路:对【X,Y】的值开根号,由于最大为 263.可以观察到最多开根号7次即为1,则当根号次数大于等于7时,这段区间值为R-L+1,还有一点是L可能大于R。

以下来自鸟神:(真是强啊)

据这一性质,我们可以得到一种解决方案:对于修改,我们对于区间内的数不全为1的区间更新,直到遇到区间内的数全部为1的区间或者叶子结点为止。这样只要使用线段树,维护区间和的信息即可。 

#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll; const int maxn = ;
ll a[maxn],sum[maxn*];
int n,m; void pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
} void buildup(int l,int r,int rt)
{
if(l==r)
{
sum[rt]=a[l];
return ;
}
int mid = (l+r)>>;
buildup(l,mid,rt<<);
buildup(mid+,r,rt<<|);
pushup(rt);
}
void update(int L,int R,int l,int r,int rt)
{
if(sum[rt]==r-l+)return ; // 剪枝
if(l==r)
{
sum[rt]=(int)sqrt(sum[rt]);
return;
}
int mid=(l+r)>>;
if(mid>=L)update(L,R,l,mid,rt<<);
if(R>mid)update(L,R,mid+,r,rt<<|);
pushup(rt);
}
ll query (int L,int R,int l,int r,int rt)
{ if(L<=l&&r<=R)
{
return sum[rt];
}
ll ans = ;
int mid=(l+r)>>;
if(mid>=L)ans+=query(L,R,l,mid,rt<<);
if(R>mid)ans+=query(L,R,mid+,r,rt<<|);
return ans;
}
int main(){
int cnt=;
while(~scanf("%d",&n))
{
printf("Case #%d:\n",++cnt);
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
}
buildup(,n,);
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int op,a,b;
scanf("%d%d%d",&op,&a,&b);
if(a>b)swap(a,b);
if(op==)
{
ll ans = query(a,b,,n,);
printf("%lld\n",ans);
}
else
{
update(a,b,,n,);
}
}
printf("\n");
}
return ;
}

HDU-4027-Can you answer these queries?线段树+区间根号+剪枝的更多相关文章

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

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

  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. HDU4027 Can you answer these queries? —— 线段树 区间修改

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

  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. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

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

随机推荐

  1. OI/ACM最全卡常大招

    NO.10: 循环展开: 在缓存和寄存器允许的情况下一条语句内大量的展开运算会刺激 CPU 并发(蛤?这是个什么原理,算了,反正写了没坏处就这么写吧) NO.9: 特殊运算优化:(或许这真的没用) 取 ...

  2. SWT 注意事项

    一:GridData (1) 将 GridData 的 widthHint 设置为0,可以解决控件大小会随着这其默认值长度大小而改变的问题.

  3. OLE--SWT高级控件

    OLE和ActiveX控件的支持    OLE(Object Link Embeded)是指在程序之间链接和嵌入对象数据.通过OLE技术可以在一个应用程序中执行其他的应用程序.    而ActiveX ...

  4. Jmeter 接口测试参数处理

    问题: 一.签名参数sign算法由文字描述,算法需自己编写 二. 参数param_json为变化的json串(json串内订单号唯一) 解决: 一. 签名sign: 1. 手动拼接后在https:// ...

  5. NLP(十四)自制序列标注平台

    背景介绍   在平时的NLP任务中,我们经常用到命名实体识别(NER),常用的识别实体类型为人名.地名.组织机构名,但是我们往往也会有识别其它实体的需求,比如时间.品牌名等.在利用算法做实体识别的时候 ...

  6. 简洁实用Socket框架DotNettySocket

    目录 简介 产生背景 使用方式 TcpSocket WebSocket UdpSocket 结尾 简介 DotNettySocket是一个.NET跨平台Socket框架(支持.NET4.5+及.NET ...

  7. [转载]线程池ThreadPoolExecutor使用简介

    一.简介 线程池类为 java.util.concurrent.ThreadPoolExecutor,常用构造方法为: ThreadPoolExecutor(int corePoolSize, int ...

  8. JSmooth 将java代码打包成exe

    JSmooth 将java代码打包成exe 前言 java代码写了这么多了,但由于jdk的限制,我只能在jdk电脑上运行项目.所以最近在研究打包exe这个问题,今天终于实现了. JSmooth下载 前 ...

  9. I firmly believe

    I firmly believe, what you plant now, you will harvest later.

  10. Golang 解决 Iris 被墙的依赖包

    使用 Golang 的 Iris web 框架时,用 go get github.com/kataras/iris 命令久久无法下载,最后还报一堆错误. 使用  GOPROXY 可解决问题,也可参考如 ...