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. Thinking In Java 4th Chap2 一切都是对象

    对基本数据类型的初始化有二: 1.String s="asdf"; 2.String s=new String("asdf"); 可能的存储区域: 寄存器(不可 ...

  2. USB协议基础知识

    ref : https://blog.csdn.net/u010142953/article/details/82627591 USB 基本知识  USB的重要关键概念:  1. 端点:位于USB设备 ...

  3. linux 安装apache

    APR and APR-Util包 下载地址:http://apr.apache.org PCRE 下载地址:http://www.pcre.org Apache Server2.4 下载地址:htt ...

  4. 通过python的selenium实现网站自动登陆留言

    from selenium import webdriver import time driver = webdriver.Chrome() driver.get('https://wordpress ...

  5. .Net C# Dictionary 和参数字符串互转

    #region Parse #region Dictionary Parse To String /// <summary> /// Dictionary Parse To String ...

  6. 简单分析FactoryBean

    1. 什么是FactoryBean FactoryBean本质上是一种Bean,只是它可以产生其他的Bean,比较特殊.在上下文getBean的时候,如果传入FactoryBean的名称,得到的是Fa ...

  7. hdu 6077多校签到

    #include <iostream> #include <cstdio> using namespace std; ][]; int f(int pos) { ; ;i< ...

  8. Scala学习十五——注解

    一.本章要点 可以为类.方法.字段.局部变量.参数.表达式.类型参数以及各种类型定义添加注解 对于表达式和类型,注解跟在被注解的条目之后 注解的形式有@Annotation.@Annotation(v ...

  9. VS219 没有.net core 3.0模板

    控制台命令 dotnet --info dotnet --version 都正常显示有安装3.0 需要升级VS 2019 16.3.3,本地版本为16.3.2

  10. js对象中属性调用.和[] 两种方式的区别

    JS 调用属性一般有两种方法——点和中括号的方法. 标准格式是对象.属性(不带双引号),注意一点的是:js对象的属性,key标准是不用加引号的,加也可以,特别的情况必须加,如果key数字啊,表达式啊等 ...