Can you answer these queries? HDU - 4027(线段树+技巧)
题意:给一个数组序列, 数组长度为100000
两种操作: 一种操作是将某一个固定区间所有数开方(向下取整)
另一种操作是询问某个区间的所有数字之和。
就是在修改的时候加一个判断即可。。
还要注意 a 可能 比 b 大
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = , INF = 0x7fffffff;
typedef long long LL;
int a, b, x, y;
LL ans; struct node{
int l, r;
LL w, f;
}Node[maxn*+]; void build(int k, int ll, int rr)
{
Node[k].l = ll, Node[k].r = rr;
if(Node[k].l == Node[k].r)
{
scanf("%lld",&Node[k].w);
return;
}
int m = (ll + rr) / ;
build(k<<, ll, m);
build(k<<|, m+, rr);
Node[k].w = Node[k*].w + Node[k*+].w;
} void chp(int k)
{
if(Node[k].l == Node[k].r)
{
Node[k].w = floor(sqrt((double)Node[k].w));
return;
}
if(Node[k].l >= a && Node[k].r <= b && Node[k].r - Node[k].l + == Node[k].w){
return;
}
// if(Node[k].f) down(k);
int m = (Node[k].l + Node[k].r) / ;
if(a <= m) chp(k<<);
if(b > m) chp(k<<|);
Node[k].w = Node[k<<].w + Node[k<<|].w;
} void qinter(int k)
{
if(Node[k].l >= a && b >= Node[k].r)
{
ans += Node[k].w;
return;
}
int m = (Node[k].l + Node[k].r) / ;
if(a <= m) qinter(k*);
if(b > m) qinter(k*+);
} int main()
{
int n, m, kase = ;
while(~scanf("%d",&n))
{
ans = ;
mem(Node, );
build(, , n);
scanf("%d",&m);
printf("Case #%d:\n",++kase);
for(int i=; i<m; i++)
{
int temp;
scanf("%d",&temp);
if(temp == )
{
scanf("%d%d",&a,&b);
if(a > b) swap(a, b);
chp();
}
else if(temp == )
{
ans = ;
scanf("%d%d",&a, &b);
if(a > b) swap(a, b);
qinter();
printf("%lld\n",ans);
}
}
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 ...
- spoj gss2 : Can you answer these queries II 离线&&线段树
1557. Can you answer these queries II Problem code: GSS2 Being a completist and a simplist, kid Yang ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- SPOJ GSS2 - Can you answer these queries II(线段树 区间修改+区间查询)(后缀和)
GSS2 - Can you answer these queries II #tree Being a completist and a simplist, kid Yang Zhe cannot ...
- Can you answer these queries III(线段树)
Can you answer these queries III(luogu) Description 维护一个长度为n的序列A,进行q次询问或操作 0 x y:把Ax改为y 1 x y:询问区间[l ...
- hdu4027Can you answer these queries?【线段树】
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- 2018.10.16 spoj Can you answer these queries V(线段树)
传送门 线段树经典题. 就是让你求左端点在[l1,r1][l1,r1][l1,r1]之间,右端点在[l2,r2][l2,r2][l2,r2]之间且满足l1≤l2,r1≤r2l1\le l2,r1 \l ...
- GSS1 - Can you answer these queries I(线段树)
前言 线段树菜鸡报告,stO ZCDHJ Orz,GSS基本上都切完了. Solution 考虑一下用线段树维护一段区间左边连续的Max,右边的连续Max,中间的连续Max还有总和,发现这些东西可以相 ...
随机推荐
- BZOJ1178 APIO2009 会议中心 贪心、倍增
传送门 只有第一问就比较水了 每一次贪心地选择当前可以选择的所有线段中右端点最短的,排序之后扫一遍即可. 考虑第二问.按照编号从小到大考虑每一条线段是否能够被加入.假设当前选了一个区间集合\(T\), ...
- Luogu4040 AHOI/JSOI2014 宅男计划 贪心、二分、三分
传送门 仍然对"为什么这个函数单峰"的问题毫无理解 首先,对于保质期又低.价格又贵的食物,我们显然不需要购买它.所以如果设\(pri_i\)表示保质期不小于\(i\)的所有食品中价 ...
- (转)Linux SSH配置和禁止Root远程登陆设置
原文 一.修改vi /etc/ssh/sshd_config 文件 1.修改默认端口:默认Port为22,并且已经注释掉了:修改是把注释去掉,并修改成其它的端口. 2.禁止root用户远程登陆:修改P ...
- linux svn代码回滚命令
取消对代码的修改分为两种情况: 第一种情况:改动没有被提交(commit). 这种情况下,使用svn revert就能取消之前的修改. svn revert用法如下: # svn revert [-R ...
- 面试2——java基础2
11.MVC设计模型 mvc设计模型是一种使用model-view-controller(模型-视图-控制器)设计创建web应用程序的模式.是一种开发模式,好处是可以将界面和业务逻辑分离. model ...
- 使用IdentityServer4实现一个简单的Oauth2客户端模式授权
1.首先新建一个webAPI项目做为IdentityServer的服务端,提供生成Token的服务,首先修改Startup.cs文件,如下图: 2.增加一个Config.cs文件,以便于提供资源和认证 ...
- Jmeter(三十三)_JsonPath表达式提取响应
我们在用jmeter做接口测试的时候,有的时候会遇到一些复杂的json响应.比如多层list嵌套时的取值 一个简单的例子: $..Name:列出所有省份 $..Province[0].Name 提取P ...
- 【亲测有效】Centos安装完成docker后启动docker报错docker: unrecognized service的两种解决方案
今天在学习Docker的时候 使用yum install docker安装完后启动不了,报错如下: [root@Sakura ~]# service docker start docker: unre ...
- Python-复习-习题-13
复习 dict: dic = {'name':'alex'}增:dic['age'] = 21 存在就覆盖dic.setdefault() 存在什么也不做,没有就增加 删除:pop()按照key删除, ...
- B. Vasya and Isolated Vertices
链接 [http://codeforces.com/contest/1065/problem/B] 题意 给你n个点,m条边,让你找最多孤立点和最少孤立点,不能有自环路 分析 对于最少max(0,n- ...