题意:给一个数组序列, 数组长度为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. Luogu3164 CQOI2014 和谐矩阵 异或高斯消元

    传送门 题意:给出$N,M$,试构造一个$N \times M$的非全$0$矩阵,其中所有格子都满足:它和它上下左右四个格子的权值之和为偶数.$N , M \leq 40$ 可以依据题目中的条件列出有 ...

  2. Ionic app 上传图片之webApi接口

    App上传图片对应的webApi服务端是怎么处理的呢? using System; using System.Collections.Generic; using System.Diagnostics ...

  3. MonkeyRunner 模块

    用python编写脚本   1.导入模块: MonkeyRunner MonkeyDevice MonkeyImage ps:如果给导入模块起别名,就应该使用别名,而不能使用原名,否则会出现错误. f ...

  4. Luogu P2482 [SDOI2010]猪国杀

    这道题在模拟界地位不亚于Luogu P4604 [WC2017]挑战在卡常界的地位了吧. 早上到机房开始写,中间因为有模拟赛一直到1点过才正式开始码. 一边膜拜CXR dalao一边写到3点左右,然后 ...

  5. SNMP基础知识

    注:本篇博客并非原创,仅是学习笔记 1. 概述1.1 诞生背景1.2 SNMP简介1.3 版本1.4 术语1.5 网络结构1.6 MIB简介2. Linux的SNMP安装 1. 概述 1.1 诞生背景 ...

  6. linux RPM manager

    RPM manage:rpm2cpio package_name | cpio -id #将一个rpm包解压至当前目录rpm -qi package_name #查看一个已安装的rpm包信息rpm - ...

  7. Wannafly挑战赛25 A.因子

    传送门 [https://www.nowcoder.com/acm/contest/197/A] 题意 给你n,m,让你求n!里有多少个m 分析 看这个你就懂了 [https://blog.csdn. ...

  8. Notes of Daily Scrum Meeting(12.23)

    今天的团队任务总结如下: 团队成员 今日团队工作 陈少杰 调试网络连接,寻找新的连接方法 王迪 建立搜索的UI界面 金鑫 查阅相关资料,熟悉后台的接口 雷元勇 建立搜索的界面 高孟烨 继续美化界面,熟 ...

  9. 个人博客week7

    IBM大型机之父佛瑞德·布鲁克斯(Frederick P. Brooks, Jr.)在1986年发表的一篇关于软件工程的经典论文,便以<没有银弹:软件工程的本质性与附属性工作>(No Si ...

  10. 【CV】ICCV2015_Unsupervised Visual Representation Learning by Context Prediction

    Unsupervised Visual Representation Learning by Context Prediction Note here: it's a learning note on ...