题意:给一个数组序列, 数组长度为100000

两种操作: 一种操作是将某一个固定区间所有数开方(向下取整)

另一种操作是询问某个区间的所有数字之和。

由于数不超过263,因此开个七八次就变成1,由于只有开方,没有修改操作,直接暴力开方,对于Node[k].w == Node[k].r - Node[k].l + 1的区间不作处理(再开也没意义了)

就是在修改的时候加一个判断即可。。

还要注意 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(线段树+技巧)的更多相关文章

  1. Can you answer these queries? HDU 4027 线段树

    Can you answer these queries? HDU 4027 线段树 题意 是说有从1到编号的船,每个船都有自己战斗值,然后我方有一个秘密武器,可以使得从一段编号内的船的战斗值变为原来 ...

  2. V - Can you answer these queries? HDU - 4027 线段树 暴力

    V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...

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

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

  5. SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并

    Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...

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

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

  8. hdu4027Can you answer these queries?【线段树】

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

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

  10. GSS1 - Can you answer these queries I(线段树)

    前言 线段树菜鸡报告,stO ZCDHJ Orz,GSS基本上都切完了. Solution 考虑一下用线段树维护一段区间左边连续的Max,右边的连续Max,中间的连续Max还有总和,发现这些东西可以相 ...

随机推荐

  1. MongoDB的地理位置查询,以及和mysql的使用对比

    MongoDB的一个特色就是具有丰富的查询接口,比如地理位置查询. 在地理位置查询上,MongoDB有着比传统关系型数据库的优势,下面举个例子. 当前移动互联网应用,按用户离目标门店距离排序上的场景很 ...

  2. JavaWeb学习总结-12 JSTL标签语言

    一 JSTL JSP标准标签库(JSTL)是一个JSP标签集合,它封装了JSP应用的通用核心功能. JSTL支持通用的.结构化的任务,比如迭代,条件判断,XML文档操作,国际化标签,SQL标签. 除了 ...

  3. 2-SAT超入门讲解

    Preface 说实话2-SAT的题目我都没怎么做过,所以这里讲的都是些超入门什么的 还有一些板子题,由于是暑假的时候学的所以有些我也记不清了 主要学习参考自:Mancher的课件&& ...

  4. Jlink使用技巧之合并烧写文件

    前言 IAP(In-application-programming),即在应用中编程.当产品发布之后,可以通过网络方便的升级固件程序,而不需要拆机下载程序.IAP系统的固件一般由两部分组成,即Boot ...

  5. Flutter - Json序列化

    这个问题,FlutterChina小组已经说明的非常清楚易懂了. 详见https://flutterchina.club/json/

  6. JDK的一个关于stack的小bug

    在一个项目中,使用了一个java.util.Stack,总所周知,栈是先入后出的,那么遍历其中元素的时候,也应该按照这个顺序遍历才对,但是实际情况确不是,以下是测试代码. Stack stack = ...

  7. Js基础---红宝书读书日记(1)-------基本类型和引用类型

    JS的变量可能包含两种不同数据类型的值,基本类型和引用类型; 基本类型是指简单的数据段,引用类型是指可能由多个值构成的对象; JS高级程序设计第三章介绍了变量分为 5种简单数据类型(string/nu ...

  8. LVS负载均衡下session共享的实现方式-持久化连接

    之前简单介绍LVS负载均衡的高可用方案实施,下面详细说明LVS的session解决方案: LVS算法中,SH算法可以实现将同一客户端的请求总是发送给第一次指定的RS,除非该RS出现故障不能再提供服务. ...

  9. Redis数据"丢失"讨论及规避和解决的几点总结

    Redis大部分应用场景是纯缓存服务,请求后端有Primary Storage的组件,如MySQL,HBase;请求Redis的键未命中,会从primary Storage中获取数据返回,同时更新Re ...

  10. SpringMVC环境搭建——HelloWorld

    1.新建Maven Web 工程: 2.添加相关的依赖包(Spring MVC.tomcat插件等),具体的pom.xml文件如下 <project xmlns="http://mav ...