题意:给n个数,m个操作,分两种操作,一种是将一段区间的每个数都开根号,另一种是查询区间和。

解题:显然对每个数开根号不能用lazy的区间更新。一个一个更新必然爆时间,对1开根号还是1,如果一段区间都是1,就不用更新了,判断r-l+1 = query()。其他都是线段树的模板。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; ll sum[*];
ll a[];
int n,m; void build(int l,int r,int rt)
{
if(l==r)
{
sum[rt]=a[l];
return;
}
int mid=(l+r)/;
build(l,mid,rt*);
build(mid+,r,rt*+); sum[rt]=sum[rt*]+sum[rt*+];
} void update(int L,int R,int l,int r,int rt)
{
if(l==r)
{
sum[rt]=sqrt(sum[rt]);
return ;
}
if( L<=l && r<=R && sum[rt]==(ll)(r-l+) )///当前区间整个都在要修改的L和R之间,并且该区间里都是1
return ;///直接返回,对每个1开根号后也是1,不变
int mid=(l+r)/;
if(L<=mid)
update(L,R,l,mid,rt*);
if(mid+<=R)
update(L,R,mid+,r,rt*+); sum[rt]=sum[rt*]+sum[rt*+];
} ll query(int L,int R,int l,int r,int rt)
{
if( L<=l && r<=R )
return sum[rt];
int mid=(l+r)/;
ll res=;
if(L<=mid)
res+=query(L,R,l,mid,rt*);
if(mid+<=R)
res+=query(L,R,mid+,r,rt*+); return res;
} int main()
{
int cnt=;
while( scanf("%d",&n)!=EOF )
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
build(,n,);
printf("Case #%d:\n",cnt++);
scanf("%d",&m);
int T,L,R;
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&T,&L,&R);
if(L>R)
swap(L,R);
if(T==)
update(L,R,,n,);
else
printf("%lld\n",query(L,R,,n,));
}
printf("\n");///坑
}
return ;
}

hdu4027-Can you answer these queries? -(线段树+剪枝)的更多相关文章

  1. HDU4027 Can you answer these queries? —— 线段树 区间修改

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

  2. HDU4027 Can you answer these queries? 线段树

    思路:http://www.cnblogs.com/gufeiyang/p/4182565.html 写写线段树 #include <stdio.h> #include <strin ...

  3. HDU4027 Can you answer these queries?(线段树 单点修改)

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

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

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

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

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

  7. HDU-4027-Can you answer these queries?线段树+区间根号+剪枝

    传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...

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

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

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

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

  10. hdu4027Can you answer these queries?(线段树)

    链接 算是裸线段树了,因为没个数最多开63次 ,开到不能再看就标记.查询时,如果某段区间被标记直接返回结果,否则继续向儿子节点更新. 注意用——int64 注意L会大于R 这点我很纠结..您出题人故意 ...

随机推荐

  1. [转帖]How long does it take to make a context switch?

    How long does it take to make a context switch?   FROM: http://blog.tsunanet.net/2010/11/how-long-do ...

  2. Unary模式下客户端创建 default-executor 和 resolver-executor 线程和从启动到执行grpc_connector_connect的主要流程

    (原创)C/C/1.25.0-dev grpc-c/8.0.0, 使用的例子是自带的例子GreeterClient 创建 default-executor 和 resolver-executor 线程 ...

  3. @Valid参数验证 BindingResult result 的使用

    1.首先导入依赖包bean-validator.jar2.在实体类上面写一些相关的验证信息:可以搜索更多的一些验证方式,这只是一部分 可以参考:点击打开链接http://blog.csdn.net/c ...

  4. 「UNR#1」奇怪的线段树

    「UNR#1」奇怪的线段树 一道好题,感觉解法非常自然. 首先我们只需要考虑一次染色最下面被包含的那些区间,因为把无解判掉以后只要染了一个节点,它的祖先也一定被染了.然后发现一次染色最下面的那些区间一 ...

  5. 在vps上搭建hexo博客

    最近更换了服务器,需要把自己的Hexo Next重新部署到新服务器上,本文记录一下在vps上搭建hexo博客的过程. 在vps上搭建hexo博客需要下面这些工具: Nginx: 用于博客展示 SSH: ...

  6. 开源规则引擎 Drools 学习笔记 之 -- 1 cannot be cast to org.drools.compiler.kie.builder.impl.InternalKieModule

    直接进入正题 我们在使用开源规则引擎 Drools 的时候, 启动的时候可能会抛出如下异常: Caused by: java.lang.ClassCastException: cn.com.cheng ...

  7. [更新] Jetbrains IntelliJ IDEA 2019 的许可证密钥

    亲测有效.转载目的:提供一种方法,当然可以看一下原网站的更新及其他方法.转载:[更新] Jetbrains IntelliJ IDEA 2019 的许可证密钥(100%工作),By Gideon    ...

  8. 总结:WPF中MultiBinding多值绑定的方法

    原文:总结:WPF中MultiBinding多值绑定的方法 一.Xaml中绑定代码: <TextBlock  Grid.Row="5" Grid.Column="3 ...

  9. js 加密方法Encrypt

    function Encrypt(str, pwd) { if (str == "") return ""; str = escape(str); if (!p ...

  10. GIT VI操作汇总

    在Git Bash Here中用命令行 pull\push\merge 代码,如果存在冲突或者自动合并时,会自动进入VI界面 1.按下 ESC 键,退出编辑模式,切换到命令模式. 2.输入 :wq , ...