https://www.luogu.org/problemnew/show/P4145

线段树区间求和 + 区间开根号

对1e9的数开根号下取整用不了几次就会<=1

因此暴力开根号,记录区间最大值是否已经<=1

#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + ; #define LL long long
#define gc getchar() int n, Ty;
LL data[N];
LL sum[N << ];
LL Max[N << ];
LL Answer; inline LL read() {
LL x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} struct Node {
#define lson jd << 1
#define rson jd << 1 | 1
void Up(int jd) {sum[jd] = sum[lson] + sum[rson]; Max[jd] = max(Max[lson], Max[rson]);}
void Build_tree(int l, int r, int jd) {
if(l == r) {sum[jd] = data[l]; Max[jd] = data[l]; return ;}
int mid = (l + r) >> ;
Build_tree(l, mid, lson);
Build_tree(mid + , r, rson);
Up(jd);
}
void Sec_G(int l, int r, int jd, int x, int y) {
if(Max[jd] <= ) return ;
if(l == r) {sum[jd] = floor(sqrt(sum[jd])); Max[jd] = sum[jd]; return ;}
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y);
if(y > mid) Sec_G(mid + , r, rson, x, y);
Up(jd);
}
void Sec_A(int l, int r, int jd, int x, int y) {
if(x <= l && r <= y) {Answer += sum[jd]; return ;}
int mid = (l + r) >> ;
if(x <= mid) Sec_A(l, mid, lson, x, y);
if(y > mid) Sec_A(mid + , r, rson, x, y);
}
}Seg_tree; int main() {
n = read();
for(int i = ; i <= n; i ++) data[i] = read();
Seg_tree.Build_tree(, n, );
Ty = read();
while(Ty --) {
int opt = read(), x = read(), y = read();
if(x > y) swap(x, y);
if(opt == ) Seg_tree.Sec_G(, n, , x, y);
else {Answer = ; Seg_tree.Sec_A(, n, , x, y); cout << Answer << "\n";}
}
return ;
}

[Luogu] 花神游历各国的更多相关文章

  1. BZOJ3211花神游历各国

    BZOJ3211花神游历各国 BZOJ luogu 分块 记一个all表示该块是否全部<=1,如果all不为真就暴力修改 因为一个数被开根的次数不多,即使\(10^{12}\)只要开根6次也会变 ...

  2. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  3. BZOJ-3211花神游历各国 并查集+树状数组

    一开始想写线段树区间开方,简单暴力下,但觉得变成复杂度稍高,懒惰了,编了个复杂度简单的 3211: 花神游历各国 Time Limit: 5 Sec Memory Limit: 128 MB Subm ...

  4. BZOJ 3211: 花神游历各国( 线段树 )

    线段树...区间开方...明显是要处理到叶节点的 之前在CF做过道区间取模...差不多, 只有开方, 那么每个数开方次数也是有限的(0,1时就会停止), 最大的数10^9开方10+次也就不会动了.那么 ...

  5. BZOJ 3211: 花神游历各国【线段树区间开方问题】

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 3514  Solved: 1306[Submit][Status][Discu ...

  6. bzoj3211花神游历各国 线段树

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 4252  Solved: 1547[Submit][Status][Discu ...

  7. 【BZOJ】【3211】花神游历各国

    线段树/暴力 线段树区间开方 唉,我傻逼了一下,TLE了一发,因为没考虑到0的情况…… 好吧简单来说一下,线段树动态查询区间和大家都会做……比较麻烦的是这次的修改变成开方了,然而这并没有什么好虚的,注 ...

  8. BZOJ3211: 花神游历各国(线段树)

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 5692  Solved: 2114[Submit][Status][Discu ...

  9. 【BZOJ3211】花神游历各国 并查集+树状数组

    [BZOJ3211]花神游历各国 Description Input Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input 41 100 5 551 1 22 1 ...

随机推荐

  1. 剑指offer42:数组和一个数字S,输出两个数的乘积最小的

    1 题目描述 输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S,如果有多对数字的和等于S,输出两个数的乘积最小的. 输出描述: 对应每个测试案例,输出两个数,小的先输出. ...

  2. python 字典所有操作

    # 字典的创建# dict1 = {}# print(type(dict1))## dict2 = {# 'name':'汪峰',# 'sex':'男',# 'hiredate':'1997-10-2 ...

  3. 【广搜】Keyboarding

    题目描述 给定一个r行c列的在电视上的“虚拟键盘”,通过“上,下,左,右,选择”共5个控制键,你可以移动电视屏幕上的光标来打印文本.一开始,光标在键盘的左上角,每次按方向键,光标总是跳到下一个在该方向 ...

  4. 关于DB2的使用(DB2数据命令)

           公司所用的数据库有金仓和DB2 首先要用命令窗口直接打开db2需要在cmd中输入:db2cmd 1:启动DB2数据库:db2start 2:连接数据库:db2 connect to  数 ...

  5. xshell和xftp过期解决办法

    去官网 xshell:https://www.netsarang.com/download/down_form.html?code=522 xftp:https://www.netsarang.com ...

  6. springboot由于bean加载顺序导致的问题

    先记录现象: dubbo整合zipkin时,我的配置文件是这样的 @Bean("okHttpSender") public OkHttpSenderFactoryBean okHt ...

  7. SpringBoot使用MongoDB异常问题

    一 环境介绍 SpringBoot1.5.13.RELEASE(本地) Spring Data MongoDB Java 8 MongoDB(青云) 二 问题描述 使用Studio3T或者Compas ...

  8. Spark RDD学习笔记

    一.学习Spark RDD RDD是Spark中的核心数据模型,一个RDD代表着一个被分区(partition)的只读数据集. RDD的生成只有两种途径: 一种是来自于内存集合或外部存储系统: 另一种 ...

  9. spring cloud EurekaClient 多网卡 ip 配置 和 源码分析(转)

    https://blog.csdn.net/qq_30062125/article/details/83856655 1.前言对于spring cloud,各个服务实例需要注册到Eureka注册中心. ...

  10. pytorch转onnx问题

    Fail to export the model in PyTorch https://github.com/onnx/tutorials/blob/master/tutorials/PytorchA ...