Can you answer these queries? HDU - 4027 有点坑
#include<iostream>
#include<cstring>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+;
ll a[N];
int n,m;
int op,l,r;
struct node
{
ll l,r;
ll sum;
}tr[N*];
void build(int root,int l, int r)
{
tr[root]={l,r};
tr[root].sum=;
if(l==r)
{
tr[root].sum=a[l];
return;
}
int mid=l+r>>;
build(root<<,l,mid);
build(root<<|,mid+,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
void update(int root,int l,int r)
{
if(l>tr[root].r||tr[root].l>r)
return;
if (tr[root].sum==(tr[root].r-tr[root].l + ))
return;
if (tr[root].l==tr[root].r)
{
tr[root].sum=sqrt(tr[root].sum);
return;
}
int mid=tr[root].l+tr[root].r>>;
update(root<<,l,r);
update(root<<|,l,r);
tr[root].sum=tr[root<<].sum+tr[root<<|].sum;
}
ll Query(int root,int l,int r)
{
if (l>tr[root].r||tr[root].l>r)
return ;
if (l<=tr[root].l&&tr[root].r<=r)
return tr[root].sum;
int mid=tr[root].l+tr[root].r>>;
ll res=;
res+=Query(root<<,l,r);
res+=Query(root<<|,l,r);
return res;
}
int main()
{
int cnt=;
while(~scanf("%d",&n))
{
printf("Case #%d:\n",++cnt);
for (int i=;i<=n;i++)
scanf("%lld",&a[i]);
scanf("%d",&m);
build(,,n);
while (m--)
{
scanf("%d%d%d",&op,&l,&r);
if(l>r)
swap(l,r);
if(op==)
update(,l,r);
else
printf("%lld\n",Query(,l,r));
}
printf("\n");
}
return ;
}
Can you answer these queries? HDU - 4027 有点坑的更多相关文章
- Can you answer these queries? HDU 4027 线段树
Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...
- V - Can you answer these queries? HDU - 4027 线段树 暴力
V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...
- Can you answer these queries? HDU - 4027 (线段树,区间开平方,区间求和)
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- Can you answer these queries? HDU - 4027(线段树+技巧)
题意:给一个数组序列, 数组长度为100000 两种操作: 一种操作是将某一个固定区间所有数开方(向下取整) 另一种操作是询问某个区间的所有数字之和. 由于数不超过263,因此开个七八次就变成1,由于 ...
- H - Can you answer these queries? ( POJ - 3264 )
H - Can you answer these queries? HDU - 4027 思路: 一眼思路:线段树区间修改,区间查询. 发现bug:区间的sqrt无法实现,所以还是相当于对区间的每 ...
- hdu 4027 Can you answer these queries?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...
- HDU 4027—— Can you answer these queries?——————【线段树区间开方,区间求和】
Can you answer these queries? Time Limit:2000MS Memory Limit:65768KB 64bit IO Format:%I64d & ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- 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 ...
随机推荐
- 实验11:EIGRP
实验8-1:EIGRP 基本配置 实验目的通过本实验可以掌握:(1)在路由器上启动EIGRP 路由进程(2)启用参与路由协议的接口,并且通告网络(3)EIGRP 度量值的计算方法(4)可行距离(FD) ...
- vs2012 编译 zlib 1.2.8
1. 下载 http://zlib.net/zlib-1.2.8.tar.gz 2. 编译 - 解压到目录,如d:\library - 开启VS2012的Command Pro ...
- 消息中间件面试题31道RabbitMQ+ActiveMQ+Kafka
消息中间件面试题31道RabbitMQ+ActiveMQ+Kafka 前言 文章开始前,我们先了解一下什么是消息中间件? 什么是中间件? 非底层操作系统软件,非业务应用软件,不是直接给最终用户使用的, ...
- 「C++ 篇」答应我,别再if/else走天下了可以吗
每日一句英语学习,每天进步一点点: "Without purpose, the days would have ended, as such days always end, in disi ...
- Codeforces_816
A.不断增加时间,直到符合要求. #include<bits/stdc++.h> using namespace std; int a,b; char c; int f(int x) { ...
- BZOJ1301 字符加密Cipher (后缀数组)
题意: 把所有循环字符串的后缀排名,输出这n<1e5个排名的最后一个字符 思路: 将该字符串拼接,按照排名顺序输出后缀开头在前一个字符串的情况中的“最后一个字符”即可 代码: #include& ...
- 腾讯云Centos服务器部署问题
在Centos7上部署Tomcat过程 下载并安装JDK 下载并部署Tomcat 打开Centos中对应的端口(默认80) 这几步操作很清楚,但首次使用Centos7时遇到了一个问题,外网无法访问服务 ...
- kali重置root密码
像这样,kali系统的root密码忘记了,只需一分钟时间,快速重置root密码 第一步: 电脑开机后kali系统会进入引导界面,这是我们只需 “e” 进入启动前编辑命令(若系统没有出现这个页面,大家在 ...
- javascript获取一个字符串的长度(包含中文)
/* getStrLen(str):获取一个字符串的长度(包含中文) */ function getStrLen(str){ let len = 0, i, c; for (i = 0; i < ...
- yum安装logstash 不生效
问题描述 根据logstash的配置方法写了一个配置文件,并放入/etc/logstash/conf.d/目录下,然后我们运行logstash # service logstash start Log ...