【题目链接】

【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. SVN CommandLine

    要是SVN命令行用不了的话: 1.SVN装了没? 2.SVN安装时,选项“command line client tools”选了没. 检出: svn checkout [-depth ARG] [- ...

  2. 79-Envelopes,包络指标.(2015.7.1)

    Envelopes 包络指标 观井映天 2015.7.1

  3. 调试24L01经验总结

    注意的地方: 1.调试24L01的时候,信号的初始状态一定要设置,否则在设置模块的状态的时候容易出错.( CE=0; CSN=1; SCK=0; MOSI = 1; IRQ = 1;)IRQ设置成1是 ...

  4. xtu summer individual-4 A - Beautiful IP Addresses

    Beautiful IP Addresses Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on Code ...

  5. [luoguP1044] 栈(数论?)

    传送门 卡特兰数 代码 #include <cstdio> int n; long long f[20]; int main() { int i; scanf("%d" ...

  6. Spring boot 搭配 JPA 生成表注释 和 字段注释

    原文地址:https://blog.csdn.net/qq_39996837/article/details/84717748 由于在数据库表反向生成过程中呢,需要通过jpa自动生成表,并且这个表必须 ...

  7. 【ZJOI2017 Round1游记】

    DAY0: 中午12点出发,下午5点到 酒店意外豪华 晚上和MG,LYY们定了个寿司套餐 没什么学习就睡觉了 DAY1: 听说RYZ在ZJ的OIer中影响颇深 讲STL的小哥真是对不住因为我是P党 D ...

  8. 洛谷——P2866 [USACO06NOV]糟糕的一天Bad Hair Day

    https://www.luogu.org/problem/show?pid=2866 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are h ...

  9. 洛谷—— P3370 【模板】字符串哈希

    P3370 [模板]字符串哈希 题目描述 如题,给定N个字符串(第i个字符串长度为Mi,字符串内包含数字.大小写字母,大小写敏感),请求出N个字符串中共有多少个不同的字符串. 友情提醒:如果真的想好好 ...

  10. HashMap的工作原理以及代码实现,为什么要转换成红黑树?

    原理参考:https://blog.csdn.net/striveb/article/details/84657326 总结: 为什么当桶中键值对数量大于8才转换成红黑树,数量小于6才转换成链表? 参 ...