题目链接

有n个数:当操作为1时求L到R的和;

当操作为0时更新L到R为原来的平方根;

不过如果仔细演算的话会发现一个2^64数的平方根开8次也就变成了 1,所以也更新不了多少次,所以可以每次更新到底。、

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#define INF 0xfffffff
#define N 100010
using namespace std; #define Lson r<<1
#define Rson r<<1|1 struct SegTree
{
int L, R;
long long sum;
int mid()
{
return (L+R)>>;
}
int len()
{
return R-L+;
}
}a[N*]; void Update(int r, int L, int R)
{
if(a[r].len()==a[r].sum)
return ;
if(a[r].L == a[r].R)//到达叶子节点;
{
a[r].sum = (long long)sqrt(a[r].sum);
return ;
}
if(R<=a[r].mid())
Update(Lson, L, R);
else if(L > a[r].mid())
Update(Rson, L, R);
else
{
Update(Lson, L, a[r].mid());
Update(Rson, a[r].mid()+, R);
}
a[r].sum = a[Rson].sum + a[Lson].sum;
} void BuildSegTree(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
if(L == R)
{
scanf("%I64d", &a[r].sum);
return;
}
BuildSegTree(Lson, L, a[r].mid());
BuildSegTree(Rson, a[r].mid()+, R); a[r].sum = a[Rson].sum + a[Lson].sum;
}
long long Query(int r, int L, int R)
{
if(a[r].L == L && a[r].R == R)
{
return a[r].sum;
}
if(L>a[r].mid())
return Query(Rson, L ,R);
else if(R <= a[r].mid())
return Query(Lson, L, R);
else
{
long long ans1 = Query(Lson, L, a[r].mid());
long long ans2 = Query(Rson, a[r].mid()+, R);
return ans1 + ans2;
}
}
int main()
{
int n, m, L, R, op, t=;
while(scanf("%d", &n) != EOF)
{
BuildSegTree(, , n);
scanf("%d", &m);
printf("Case #%d:\n", t++);
while(m--)
{
scanf("%d%d%d", &op, &L, &R);
if(L>R)swap(L, R);//L和R的大小没说;
if(op==)
Update(, L, R);
else
{
long long ans=Query(, L, R);
printf("%I64d\n", ans);
}
}
printf("\n");
}
return ;
}

Can you answer these queries?---hdu4027的更多相关文章

  1. (线段树 区间查询更新) Can you answer these queries? -- hdu--4027

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4027 分析:因为这个操作是把一个数变成平方根,所以显得略棘手,不过如果仔细演算的话会发现一个2^64数的 ...

  2. Can you answer these queries?-HDU4027 区间开方

    题意: 给你n个数,两个操作,0为区间开方,1为区间求和 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 思路: 如果当该区间的数都为1,我们没必要 ...

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

  5. kuangbin专题七 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 ...

  6. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  7. hdu 4027 Can you answer these queries?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4027 Can you answer these queries? Description Proble ...

  8. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  9. GSS7 spoj 6779. Can you answer these queries VII 树链剖分+线段树

    GSS7Can you answer these queries VII 给出一棵树,树的节点有权值,有两种操作: 1.询问节点x,y的路径上最大子段和,可以为空 2.把节点x,y的路径上所有节点的权 ...

随机推荐

  1. mysql5.6.34-debug Source distribution在树莓派下编译的几个错误

    raspberrypi下编译mysql5.6 debug版源码. 1. 启动错误 和mysqld相关的文件及文件夹权限必须设置为mysql用户可读可写可执行,特别是/var/run/mysqld/目录 ...

  2. 《C++ Primer Plus》第17章 输入、输出和文件 学习笔记

    流是进出程序的字节流.缓冲区是内存中的临时存储区域,是程序与文件或其他I/O设备之间的桥梁.信息在缓冲区和文件之间传输时,将使用设备(如磁盘驱动器)处理效率最高的尺寸以大块数据的方式进行传输.信息在缓 ...

  3. 服务器搭建--Linux安装erlang

    1.安装依赖环境: 1)安装GCC GCC-C++ Openssl等模块,安装过就不需要安装了 yum -y install make gcc gcc-c++ kernel-devel m4 ncur ...

  4. 【angularjs基础】ng-repeat嵌套循环报错angular.min.js:89 Error: [ngRepeat:dupes]

    再写嵌套循环的时候,提示一个错误 angular.min.js: Error: [ngRepeat:dupes] 代码如下 <table class="GridViewTable mt ...

  5. 深入学习Make命令和Makefile(下)

    https://www.zybuluo.com/lishuhuakai/note/209300 make是Linux下的一款程序自动维护工具,配合makefile的使用,就能够根据程序中模块的修改情况 ...

  6. CF510B Fox And Two Dots(搜索图形环)

    B. Fox And Two Dots time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十二:串口模块① — 发送

    实验十二:串口模块① — 发送 串口固然是典型的实验,想必许多同学已经作烂,不过笔者还要循例介绍一下.我们知道串口有发送与接收之分,实验十二的实验目的就是实现串口发送,然而不同的是 ... 笔者会用另 ...

  8. linux编码问题小节

    今天又碰到了难缠的python编码问题,首先主要还是linux操作系统中的编码问题. 无论怎么样,我都没办法在linux的vim中利用中文输入法打出中文? vim中的set encoding,set ...

  9. 23种设计模式之责任链模式(Chain of Responsibility)

    责任链模式是一种对象的行为型模式,避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到有对象处理它为止.责任链模式不保证每个请求都被接受, ...

  10. 在linux上执行.net Console apps

    有个程序,在.net下写了半天,总算跑起来了,发现有个问题,在windows上不好弄,而同事前一段时间已经有Linux下的解决方法了,于是想直接将.net程序放在linux下运行 在linux上的mo ...