【题目链接】

【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. Python之面向对象封装

    Python之面向对象封装 封装不是单纯意义的隐藏 什么是封装: 将数据放在一个设定好的盒子里,并标出数据可以实现的功能,将功能按钮外露,而隐藏其功能的工作原理,就是封装. 要怎么封装: 你余额宝有多 ...

  2. 4. GC 算法(实现篇) - GC参考手册

    您应该已经阅读了前面的章节: 垃圾收集简介 - GC参考手册 Java中的垃圾收集 - GC参考手册 GC 算法(基础篇) - GC参考手册 学习了GC算法的相关概念之后, 我们将介绍在JVM中这些算 ...

  3. IDEA-基本设置

    目录: 1.设置内存 2.设置编码格式 3.设置换行符 4.设置新建Class文档说明 5.添加自定义注释 6.设置自己的maven 工欲善其事,必先利其器,设置好基础的设置才能事半功倍!少踩坑!以下 ...

  4. 【bzoj1965】[Ahoi2005]SHUFFLE 洗牌 - 快速幂

    为了表彰小联为Samuel星球的探险所做出的贡献,小联被邀请参加Samuel星球近距离载人探险活动. 由于Samuel星球相当遥远,科学家们要在飞船中度过相当长的一段时间,小联提议用扑克牌打发长途旅行 ...

  5. Ftp启动与关闭

    //启动 service vsftpd start //关闭 service vsftpd stop 查看进程 ps -ef | grep ftp root : ? :: /usr/sbin/vsft ...

  6. 2.5 3-way quickSort

    1.排序时,数组含有大量重复元素,应该使用哪种排序手段? (1)mergeSort:与数组的特征无关,比较次数总是在1/2NlgN~NlgN之间 (2)quickSort:当所有的元素全都相同的时候, ...

  7. Thinkphp5.0 的视图view的模板布局

    Thinkphp5.0 的视图view的模板布局 使用include,文件包含: <!-- 头部 --> <div class="header"> {inc ...

  8. The Java library for converting Wikipedia wikitext notation to HTML

    https://code.google.com/p/gwtwiki/ The Java Wikipedia API (Bliki engine) is a parser library for con ...

  9. HDU——3072 Intelligence System

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. Eclipse 搭建tomcat+动态项目完整版

    1. Tomcat搭建 1.新加服务器,右击控制台的server目录->new->server->选择本地tomcat 2.配置tomcat属性(如果更改失败,将tomcat下的项目 ...