【题目链接】

【BZOJ 3211】 点击打开链接

【BZOJ 3038】 点击打开链接

【算法】

线段树

开根操作直接开到叶子节点,注意当区间中所有数都是0或1时,不需要开根

【代码】

#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010 int i,n,m,opt,l,r;
long long a[MAXN]; struct SegmentTree
{
struct Node
{
int l,r;
long long sum;
bool flag;
} Tree[MAXN<<];
inline void update(int index)
{
Tree[index].sum = Tree[index<<].sum + Tree[index<<|].sum;
Tree[index].flag = Tree[index<<].flag & Tree[index<<|].flag;
}
inline void build(int index,int l,int r)
{
int mid;
Tree[index].l = l; Tree[index].r = r;
if (l == r)
{
Tree[index].sum = a[l];
if (a[l] == || a[l] == ) Tree[index].flag = true;
else Tree[index].flag = false;
return;
}
mid = (l + r) >> ;
build(index<<,l,mid);
build(index<<|,mid+,r);
update(index);
}
inline void modify(int index,int l,int r)
{
int mid;
if (Tree[index].flag) return;
if (Tree[index].l == Tree[index].r)
{
Tree[index].sum = (long long)sqrt(Tree[index].sum);
if (Tree[index].sum == || Tree[index].sum == ) Tree[index].flag = true;
return;
}
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) modify(index<<,l,r);
else if (mid + <= l) modify(index<<|,l,r);
else
{
modify(index<<,l,mid);
modify(index<<|,mid+,r);
}
update(index);
}
inline long long query(int index,int l,int r)
{
int mid;
if (Tree[index].l == l && Tree[index].r == r) return Tree[index].sum;
mid = (Tree[index].l + Tree[index].r) >> ;
if (mid >= r) return query(index<<,l,r);
else if (mid + <= l) return query(index<<|,l,r);
else return query(index<<,l,mid) + query(index<<|,mid+,r);
}
} T;
template <typename T> inline void read(T &x)
{
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x)
{
if (x < )
{
putchar('-');
x = -x;
}
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x)
{
write(x);
puts("");
} int main() { read(n);
for (i = ; i <= n; i++) read(a[i]);
T.build(,,n);
read(m);
while (m--)
{
read(opt);
if (opt == )
{
read(l); read(r);
writeln(T.query(,l,r));
} else
{
read(l); read(r);
T.modify(,l,r);
}
}
return ; }

【BZOJ 3211&3038】 花神游历各国 & 上帝造题的七分钟2的更多相关文章

  1. 【BZOJ3211&3038】花神游历各国&上帝造题的七分钟2(CodeVS)

    Description   Input   Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input 4 1 100 5 5 5 1 1 2 2 1 2 1 1 2 2 ...

  2. BZOJ 3038: 上帝造题的七分钟2 / BZOJ 3211: 花神游历各国 (线段树区间开平方)

    题意 给出一些数,有两种操作.(1)将区间内每一个数开方(2)查询每一段区间的和 分析 普通的线段树保留修改+开方优化.可以知道当一个数为0或1时,无论开方几次,答案仍然相同.所以设置flag=1变表 ...

  3. [bzoj3038/3211]上帝造题的七分钟2/花神游历各国_线段树

    上帝造题的七分钟2 bzoj-3038 题目大意:给定一个序列,支持:区间开方:查询区间和. 注释:$1\le n\le 10^5$,$1\le val[i] \le 10^{12}$. 想法:这题还 ...

  4. bzoj3211花神游历各国&&bzoj3038上帝造题的七分钟2*

    bzoj3211花神游历各国 题意: n个数的序列,m个操作,操作两种:区间开根(向下取整)和区间求和.n≤100000,m≤200000,序列中的数非负且≤109. 题解: 一个≤109的数开6次根 ...

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

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

  6. 题解 洛谷 P4145 【上帝造题的七分钟2 / 花神游历各国】

    题目 上帝造题的七分钟2 / 花神游历各国 题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. ...

  7. 洛谷P4145 上帝造题的七分钟2/花神游历各国 [树状数组,并查集]

    题目传送门 题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是 ...

  8. 【bzoj3211】花神游历各国&&【bzoj3038】上帝造题的七分钟2

    bzoj3038]上帝造题的七分钟2 Description XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. “第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟, ...

  9. 洛谷P4145——上帝造题的七分钟2 / 花神游历各国

    题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...

随机推荐

  1. Linux高阶命令进阶

    1. 输出重定向 > (1>):覆盖输出,会覆盖掉原先的文件内容 >> (1>>) :追加输出,不会覆盖原始文件内容,会在原始内容末尾继续添加 2> :错误输 ...

  2. 树莓派 -- oled 续(1) wiringPi

    在上文中,分析了wiringPi 的oled demo是使用devfs来控制spi master和spi slave通讯. https://blog.csdn.net/feiwatson/articl ...

  3. MyBaties异常之 ORA-00918: 未明确定义列

    原因: 如果a表与b表连接,且a与b中存在两个相同的字段,则必须指明字段是哪个表的 箭头所致位置没有指定ROOM_ID为那个表的,应修改为t1.ROOM_ID

  4. 记一次C++编程引用obj文件作为静态库文件

    简介 常用静态库文件的名字一般是 ***.lib ,例如 nisyscfg.lib 就是一个静态库文件,但是一个例程居然是引用 **.obj 文件作为静态库,有点非常规啊. 这是一个NI488.2 的 ...

  5. Fiddler基本用法:手机抓包

    from:https://blog.csdn.net/gld824125233/article/details/52588275 电脑最好是笔记本,这样能和手机保持统一局域网内:其他不多说,直接说步骤 ...

  6. Python条件判断(if)

    Python条件判断(if) 一.基本介绍 1.Python 编程中 if 语句用于控制程序的执行,基本形式为: if 判断条件: 执行语句…… 需要注意的是,Python没有像其他大多数语言一样使用 ...

  7. Leetcode 204计数质数

    计数质数 统计所有小于非负整数 n 的质数的数量. 示例: 输入: 10 输出: 4 解释: 小于 10 的质数一共有 4 个, 它们是 2, 3, 5, 7 . 比计算少n中素数的个数. 素数又称质 ...

  8. 防火墙内设置FileZilla Server注意事项

    开启了Windows下的防火墙,如何设置FileZilla Server 相关选项,能在服务器端只开启21,23端口就可以正常连接使用 方法/步骤   1.       开启windows防火墙,同时 ...

  9. 【BZOJ1070】修车(费用流)

    题意:同一时刻有N位车主带着他们的爱车来到了汽车维修中心. 维修中心共有M位技术人员,不同的技术人员对不同的车进行维修所用的时间是不同的. 现在需要安排这M位技术人员所维修的车及顺序,使得顾客平均等待 ...

  10. Spring Boot - how to configure port

    https://stackoverflow.com/questions/21083170/spring-boot-how-to-configure-port