BZOJ 3211 花神游历各国 线段树平方开根
题目链接:
https://www.lydsy.com/JudgeOnline/problem.php?id=3211
题目大意:


思路:
由于数据范围只有1e9,一个数字x开根号次数超过logx之后均为1,所以可以暴力开根号,但是需要剪枝优化,如果子树的max小于等于1,那么直接跳过即可。否则递归到叶子节点暴力开根号。
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);//不可再使用scanf printf
#define Max(a, b) ((a) > (b) ? (a) : (b))//禁用于函数,会超时
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Mem(a) memset(a, 0, sizeof(a))
#define Dis(x, y, x1, y1) ((x - x1) * (x - x1) + (y - y1) * (y - y1))
#define MID(l, r) ((l) + ((r) - (l)) / 2)
#define lson ((o)<<1)
#define rson ((o)<<1|1)
#define Accepted 0
#pragma comment(linker, "/STACK:102400000,102400000")//栈外挂
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} typedef long long ll;
const int maxn = + ;
const int MOD = ;//const引用更快,宏定义也更快
const int INF = 1e9 + ;
const double eps = 1e-; ll a[maxn];
struct node
{
int l, r;
ll mmax, sum;
}tree[maxn<<];
void build(int o, int l, int r)
{
tree[o].l = l, tree[o].r = r;
if(l == r)
{
tree[o].mmax = tree[o].sum = a[l];
return;
}
int m = MID(l, r);
build(lson, l, m);
build(rson, m + , r);
tree[o].mmax = Max(tree[lson].mmax, tree[rson].mmax);
tree[o].sum = tree[lson].sum + tree[rson].sum;
}
int ql, qr;
ll sum;
void query(int o)
{
if(ql <= tree[o].l && qr >= tree[o].r)
{
sum += tree[o].sum;
return;
}
if(ql <= tree[lson].r)query(lson);
if(qr >= tree[rson].l)query(rson);
}
void update(int o)
{
if(tree[o].mmax <= )return;
if(tree[o].l == tree[o].r)
{
tree[o].mmax = tree[o].sum = sqrt(1.0 * tree[o].mmax);
return ;
}
if(ql <= tree[lson].r)update(lson);
if(qr >= tree[rson].l)update(rson);
tree[o].mmax = Max(tree[lson].mmax, tree[rson].mmax);
tree[o].sum = tree[lson].sum + tree[rson].sum;
}
int main()
{
int n, m;
scanf("%d", &n);
for(int i = ; i <= n; i++)scanf("%d", &a[i]);
build(, , n);
scanf("%d", &m);
while(m--)
{
int op;
scanf("%d%d%d", &op, &ql, &qr);
if(op == )
{
sum = ;
query();
printf("%lld\n", sum);
}
else
{
update();
}
}
return Accepted;
}
BZOJ 3211 花神游历各国 线段树平方开根的更多相关文章
- BZOJ 3211: 花神游历各国( 线段树 )
线段树...区间开方...明显是要处理到叶节点的 之前在CF做过道区间取模...差不多, 只有开方, 那么每个数开方次数也是有限的(0,1时就会停止), 最大的数10^9开方10+次也就不会动了.那么 ...
- BZOJ 3038: 上帝造题的七分钟2 / BZOJ 3211: 花神游历各国 (线段树区间开平方)
题意 给出一些数,有两种操作.(1)将区间内每一个数开方(2)查询每一段区间的和 分析 普通的线段树保留修改+开方优化.可以知道当一个数为0或1时,无论开方几次,答案仍然相同.所以设置flag=1变表 ...
- BZOJ 3211 花神游历各国 (树状数组+并查集)
题解:首先,单点修改求区间和可以用树状数组实现,因为开平方很耗时间,所以在这个方面可以优化,我们知道,开平方开几次之后数字就会等于1 ,所以,用数组记录下一个应该开的数,每次直接跳到下一个不是1的数字 ...
- BZOJ 3211: 花神游历各国【线段树区间开方问题】
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3514 Solved: 1306[Submit][Status][Discu ...
- bzoj3211: 花神游历各国(线段树) 同codevs2492
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3628 Solved: 1326[Submit][Status][Discu ...
- bzoj3211花神游历各国 线段树
3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 4252 Solved: 1547[Submit][Status][Discu ...
- GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)
GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...
- bzoj3211 花神游历各国 线段树,势能分析
[bzoj3211]花神游历各国 2014年3月17日2,7230 Description Input Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input ...
- bzoj 3211: 花神游历各国
#include<cstdio> #include<cmath> #include<iostream> #define M 100006 using namespa ...
随机推荐
- 4.java设计模式-原型模式(prototype)
在<JAVA与模式>一书中开头是这样描述原型(Prototype)模式的: 原型模式属于对象的创建模式.通过给出一个原型对象来指明所有创建的对象的类型,然后用复制这个原型对象的办法创建出更 ...
- groovy普通方法、抽象方法、接口、trait
/** * Created by Jxy on 2018/12/21 14:07 * trait关键字 * 声明trait中的方法和任何常规方法一样 * trait声明抽象方法需要在实现类中实现 * ...
- java:模拟队列操作
import java.util.LinkedList; public class Myqueue { private LinkedList<Object> linkedList; pub ...
- HDU 2955(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=2955 这道题求不被抓时的最大金钱.金额是整数,概率是小数.因为数组小标不能是小数,所以我们可以以钱作为weigh ...
- Eclipse设置虚拟机参数 (转 构建内存溢出)
Java -verbose:gc 中参数-verbose:gc 表示输出虚拟机中GC的详细情况. 首先在Eclipse的Debug页签中设置虚拟机参数: 步骤: 1.选中已经写好的项目 2.Run-& ...
- PowerDesigner16导出SQL时如何添加注释
添加注释方法 https://jingyan.baidu.com/article/47a29f24652e44c0142399c3.html 重点是修改value的值 alter table [%QU ...
- sql:MySql create FUNCTION,VIEW,PROCEDURE
use geovindu; #函数 DELIMITER $$ drop function if exists f_GetDepartmentName $$ CREATE function f_GetD ...
- python查看当前路径
1.os模块 import os print os.getcwd() #获取当前工作目录路径 print os.path.abspath('.') #获取当前工作目录路径 print os.path. ...
- Lucas定理及扩展
Lucas定理 不会证明... 若\(p\)为质数 则\(C(n, m)\equiv C(n/p, m/p)*C(n\%p, m\%p)(mod\ p)\) 扩展 求 \(C(n,m)\) 模 \(M ...
- Spring与Web整合
一 概述 1.整合目的 将所有对象的创建与管理任务交给Spring容器,降低程序的耦合度. 2.整合途径 将Spring容器注入到Web容器中. 3.具体实现 使用ServletContextList ...