线段树...区间开方...明显是要处理到叶节点的

之前在CF做过道区间取模...差不多, 只有开方, 那么每个数开方次数也是有限的(0,1时就会停止), 最大的数10^9开方10+次也就不会动了.那么我们线段树多记个max就可以少掉很多不必要的操作

--------------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
  
#define rep(i, n) for(int i = 0; i < n; i++)
#define M(l, r) (((l) + (r)) >> 1)
#define clr(x, c) memset(x, c, sizeof(x))
  
using namespace std;
 
typedef long long ll;
 
const int maxn = 100009;
 
struct Node {
Node *l, *r;
int v, mx;
ll sum;
Node():mx(0) {
l = r = NULL;
}
inline void update() {
if(l) {
mx = max(l->mx, r->mx);
sum = l->sum + r->sum;
} else
   sum = mx = v;
}
} pool[maxn << 1], *pt = pool, *root;
 
int L, R, n, seq[maxn];
 
void build(Node* t, int l, int r) {
if(r > l) {
int m = M(l, r);
build(t->l = pt++, l, m);
build(t->r = pt++, m + 1, r);
} else
   t->v = seq[l];
t->update();
}
 
void modify(Node* t, int l, int r) {
if(t->mx <= 1) return;
if(l == r)
t->v = floor(sqrt(t->v));
else {
int m = M(l, r);
if(L <= m) modify(t->l, l, m);
if(m < R) modify(t->r, m + 1, r);
}
t->update();
}
 
ll query(Node* t, int l, int r) {
if(L <= l && r <= R)
   return t->sum;
int m = M(l, r);
return (L <= m ? query(t->l, l, m) : 0 ) + (m < R ? query(t->r, m + 1, r) : 0);
 
int main() {
// freopen("test.in", "r", stdin);
cin >> n;
for(int i = 1; i <= n; i++) 
   scanf("%d", seq + i);
build(root = pt++, 1, n);
int m, op;
cin >> m;
while(m--) {
scanf("%d%d%d", &op, &L, &R);
if(op == 1)
printf("%lld\n", query(root, 1, n));
else 
   modify(root, 1, n);
}
return 0;
}

--------------------------------------------------------------------------------------------

3211: 花神游历各国

Time Limit: 5 Sec  Memory Limit: 128 MB
Submit: 1414  Solved: 546
[Submit][Status][Discuss]

Description

Input

Output

每次x=1时,每行一个整数,表示这次旅行的开心度

Sample Input

4

1 100 5 5

5

1 1 2

2 1 2

1 1 2

2 2 3

1 1 4

Sample Output

101

11

11

HINT

对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9

Source

BZOJ 3211: 花神游历各国( 线段树 )的更多相关文章

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

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

  2. BZOJ 3211 花神游历各国 线段树平方开根

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3211 题目大意: 思路: 由于数据范围只有1e9,一个数字x开根号次数超过logx之后 ...

  3. BZOJ 3211 花神游历各国 (树状数组+并查集)

    题解:首先,单点修改求区间和可以用树状数组实现,因为开平方很耗时间,所以在这个方面可以优化,我们知道,开平方开几次之后数字就会等于1 ,所以,用数组记录下一个应该开的数,每次直接跳到下一个不是1的数字 ...

  4. BZOJ 3211: 花神游历各国【线段树区间开方问题】

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 3514  Solved: 1306[Submit][Status][Discu ...

  5. bzoj3211: 花神游历各国(线段树) 同codevs2492

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 3628  Solved: 1326[Submit][Status][Discu ...

  6. bzoj3211花神游历各国 线段树

    3211: 花神游历各国 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 4252  Solved: 1547[Submit][Status][Discu ...

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

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

  8. bzoj3211 花神游历各国 线段树,势能分析

    [bzoj3211]花神游历各国 2014年3月17日2,7230 Description   Input   Output 每次x=1时,每行一个整数,表示这次旅行的开心度 Sample Input ...

  9. Codeforces 920F. SUM and REPLACE / bzoj 3211 花神游历各国

    题目大意: 一个数列 支持两种操作 1 把区间内的数变成他们自己的约数个数 2 求区间和 思路: 可以想到每个数最终都会变成2或1 然后我们可以线段树 修改的时候记录一下每段有没有全被修改成1或2 是 ...

随机推荐

  1. 关于Unix时间戳

    如何在不同编程语言中获取现在的Unix时间戳(Unix timestamp)? Java time JavaScript Math.round(new Date().getTime()/1000)ge ...

  2. 一些常用的Intent及intent-filter的信息

    Uri Action 功能 备注 geo:latitude,longitude Intent.ACTION_VIEW 打开地图应用程序并显示指定的经纬度   geo:0,0?q=street+addr ...

  3. 两种方式在Tableau Desktop 中创建子弹图(Bullet Chart)

    子弹图,顾名思义是由于该类信息图的样子很想子弹射出后带出的轨道.起初,子弹图的发展是为了取代仪表盘上常见的那种里程表,时速表等基于圆形的信息表达方式.子弹图无修饰的线性表达方式使我们能够在狭小的空间中 ...

  4. Oracle Hint用法总结

    1. /*+ALL_ROWS*/ 表明对语句块选择基于开销的优化方法,并获得最佳吞吐量,使资源消耗最小化. 例如: SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_I ...

  5. plsql 的循环之 goto

    实例: /* 测试goto 的用法, */ procedure test_loop_go(pi_aab001 in number, po_fhz out varchar2, po_msg out va ...

  6. Linux android studio :'tools.jar' seems to be not in Android Studio classpath.

    问题: 'tools.jar' seems to be not in Android Studio classpath.Please ensure JAVA_HOME points to JDK ra ...

  7. paip.php-gtk 桌面程序 helloworld总结

    paip.php-gtk 桌面程序 helloworld总结 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.cs ...

  8. codility上的练习 (1)

    codility上面添加了教程.目前只有lesson 1,讲复杂度的……里面有几个题, 目前感觉题库的题简单. tasks: Frog-Jmp: 一只青蛙,要从X跳到Y或者大于等于Y的地方,每次跳的距 ...

  9. sqlite3 脚本的使用

    本来想找个专门查看数据库的工具的,后来发现脚本也非常easy,就直接用脚本了. sqlite3的脚本能够方便的查看当前数据库里的内容,使用起来事实上非常easy,这一列举一些最简单的使用方法,以后假设 ...

  10. CentOS中使用shell的命令补全

    习惯debian的用户都知道shell中的自动补全功能非常实用,其中在CentOS中也可以有同样的功能. 只需要安装 bash-completion 包即可. rpm -ivh http://www. ...