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. CF网络流练习

    1. 103E 大意: 给定$n$个集合, 满足对于任意的$k$, 任意$k$个集合的并集都不少于$k$. 要求选出$k$个集合$(k> 0)$, 使得并恰好等于$k$, 输出最少花费. Hal ...

  2. 系统学习机器学习之神经网络(三)--GA神经网络与小波神经网络WNN

    系统学习机器学习之神经网络(三)--GA神经网络与小波神经网络WNN 2017年01月09日 09:45:26 Eason.wxd 阅读数 14135更多 分类专栏: 机器学习   1 遗传算法1.1 ...

  3. Mybatis 多个参数传入的多种方法

    ist<XXXBean> getXXXBeanList(HashMap map); <select id="getXXXBeanList" parameterTy ...

  4. git merge 命令的使用

    我们把dev分支的工作成果合并到master分支上: $ git merge dev Updating d46f35e..b17d20e Fast-forward readme.txt | 1 + 1 ...

  5. asp.net core 中hangfire面板的配置及使用

    1.定义校验授权类DyDashboardAuthorizationFilter /// <summary> /// Hangfire仪表盘配置授权 /// </summary> ...

  6. JS-实现横向手风琴

    横向手风琴-- 鼠标悬浮某一张图片,图片显示,其他图片影藏. <div class="content"> <ul> <li class="c ...

  7. bash shell脚本之使用expr运算

    bash shell中的数学运算 cat test7: #!/bin/bash # An example of using the expr command var1= var2= var3=`exp ...

  8. IDEA GIT 忽略文件

    1.装插件 .igore 2.新建忽略文件格式 3.编辑忽略后缀文件 可以是文件夹 也可以是 具体文件类型

  9. JAVA 1.6锁状态转换

    JVM 学不好 并发就学不好 面试问题 Object 有哪些方法 syn实现过程 wait notify 为什么要设计到Object上而不是接口?虽然可以 但是面向对象的思想 子类 object.wa ...

  10. element之tree组件样式重写

    1.改写实现效果: 2.页面代码 <el-tree :data="data" :props="defaultProps" @node-click=&quo ...