题目

题意:

  初始给你n个数,通过m个操作,  操作0是使区间范围内的每一个a[i]都变成 根号a[i] ,操作1是查询区间范围内数字的和。

思路:

  如果一个节点sum[rt]是1的话,根号1还是1,重复遍历这个节点会大大增加计算次数。n和区间左右端点的范围都 <=1e5,所以一个节点最多遍历不超过10次。

  如果这个节点sum[rt]是1,那么标记这个节点vis[rt]=1,说明这个节点以后不用往下遍历了。如果一个节点的左右子节点vis[rt<<1]=1, vis[rt<<1|1]==1,那么vis[rt]=1。注意longlong 以及输入要多空一行。

#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
const ll mod=1e9+;
const int INF= 0x3f3f3f3f;
const int N=1e5+; ll add[N<<],sum[N<<];
ll a[N<<];
int vis[N<<]; /*
struct node
{
int v,p;
}b[N<<2]; bool cmp(node x,node y)
{
return x.v<y.v;
}*/ void push_up(int rt)
{
sum[rt] = sum[rt<<] + sum[rt<<|] ;
vis[rt] = vis[rt<<] & vis[rt<<|] ; //左右子节点的vis都是1 父节点才是1
}
/*
void push_down(int rt,int ln ,int rn)
{
if(add[rt])
{
add[rt<<1]=add[rt<<1|1]=add[rt];
sum[rt<<1]=add[rt]*ln;
sum[rt<<1|1]=add[rt]*rn;
add[rt]=0;
}
}*/
void Built(int l,int r,int rt)
{
if(l==r)
{
sum[rt]=a[l];
if(sum[rt]<=) vis[rt]=;
return;
}
int m=l+r>>;
Built(l,m,rt<<);
Built(m+,r,rt<<|);
push_up(rt);
} void update(int x,int y,int l,int r,int rt)
{
if(l==r)
{
sum[rt]= 1LL*sqrt(sum[rt]*1.0);
if( sum[rt]<= ) vis[rt]=;
return;
}
int m=l+r>>;
//push_down(rt,m-l+1,r-m);
if(x<=m && !vis[rt<<]) update(x,y,l,m,rt<<);
if(m<y && !vis[rt<<|]) update(x,y,m+,r,rt<<|);
push_up(rt);
} ll Query(int x,int y, int l,int r,int rt)
{
if(x<=l && r<=y)
{
return sum[rt];
}
int m=l+r>>;
//push_down(rt,m-l+1,r-m);
ll ans=;
if(x<=m) ans+=Query(x,y,l,m,rt<<);
if(m<y) ans+=Query(x,y,m+,r,rt<<|);
return ans;
}
int main()
{
int x,y,c=,n,m,q;
while(~scanf("%d",&n) )
{
/*for(int i=1;i<=n;i++) scanf("%d",&b[i].v),b[i].p=i;
sort(b+1,b+1+n,cmp);
int cnt=0;
for(int i=1;i<=n;i++)
{
if(b[i].v != b[i-1].v)
cnt++;
a[b[i].p]=cnt;
}//离散化完毕 */
for(int i=;i<=n;i++) scanf("%lld",&a[i]);
mem(vis,);
mem(sum,);
Built(,n,);
scanf("%d",&m);
printf("Case #%d:\n",++c);
while(m--)
{
scanf("%d%d%d",&q,&x,&y);
if(x>y) swap(x,y);
if(q==)
update(x,y,,n,);
else
printf("%lld\n",Query(x,y,,n,) );
}
cout<<endl;
} }

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

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

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

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

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

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

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

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

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

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

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

  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. win7/win10 设置始终以管理员身份运行cmd窗口

    在桌面上找到cmd快捷方式图标,右键"属性" 4.选择"快捷方式",点击“高级” 5.勾选用管理员身份运行,点击"确定" 6.点击" ...

  2. 【Python开发】C和Python之间的接口实现

    作者:Jerry Jho 链接:https://www.zhihu.com/question/23003213/answer/56121859 ## 更新:关于ctypes,见拙作 聊聊Python ...

  3. php_mvc实现步骤九(登录验证码,退出-登录标记)

    shop34-17-登录验证码 验证码的分析 登录:防止暴力破解 论坛:防止灌水水 展示类:被抓取. 需要技术: 图片处理技术. 会话session技术. PHP图片处理技术 – GD 具体操作步骤 ...

  4. 【转】Fuel 9.0安装Openstack网络验证失败解决

    原文链接:https://blog.csdn.net/wiborgite/article/details/52983575 故障现象: 网络验证失败,报错信息如下: Repo availability ...

  5. Linux系统下Redis单机版的安装详细教程

    Linux系统下Redis单机版的安装详细教程 1.下载软件安装包并上传到root目录 这里以旧版本的3.0进行安装,比较成熟稳定,具体软件可以通过qq群534073451文件下载

  6. 程序员生存之道,多写bug!

    1.代码写得好,bug少,看起来就像闲人. 2.注释多,代码清晰,任何人接手非常方便,看起来谁都都可以替代. 3.代码写得烂,每天风风火火改bug,各种救火,解决各种线上重大问题,于是顺理成章为公司亮 ...

  7. lmir 随笔

    近期需要研究一些特征工程的工作,就打算把微软之前公布出来的特征都复现一遍,今天遇到的特征是 LMIR, 其实也就是language model for information retrieval的简写 ...

  8. 阅读笔记——《How a Facebook rejection pushed me to start and grow a profitable business in 12 months》

    阅读笔记——<How a Facebook rejection pushed me to start and grow a profitable business in 12 months> ...

  9. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): 错误解决

    报错信息:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 说明:这段报错信息表示 Map ...

  10. SpringCloud整合过程中jar依赖踩坑经验

    今天在搭建SpringCloud Eureka过程中,一直在报pom依赖错误,排查问题总结如下经验. 1.SpringBoot整合SpringCloud两者版本是有严格约束的,详细见SpringBoo ...