SPOJ2713GSS4 - Can you answer these queries IV(线段树)
题意

Sol
讲过无数次了。。很显然,一个$10^12$的数开方不超过$8$次后就会变为$1$
因此直接暴力更改即可,维护一下这段区间是否被全改为了$1$
双倍经验:https://www.luogu.org/problemnew/show/P4145
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#define int long long
#define Pair pair<int, int>
#define fi first
#define se second
#define MP(x, y) make_pair(x, y)
using namespace std;
const int MAXN = 1e6 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M;
int a[MAXN];
#define ls k << 1
#define rs k << 1 | 1
struct Node {
int l, r, w, f;
}T[MAXN];
void update(int k) {
if(T[ls].f && T[rs].f) T[k].f = ;
T[k].w = T[ls].w + T[rs].w;
}
void Build(int k, int ll, int rr) {
T[k] = (Node) {ll, rr};
if(ll == rr) {
T[k].w = a[ll];
return ;
}
int mid = ll + rr >> ;
Build(ls, ll, mid);
Build(rs, mid + , rr);
update(k);
}
void push(int k) {
if(T[k].f) return ;
if(T[k].l == T[k].r) {
T[k].w = sqrt(T[k].w);
if(T[k].w == ) T[k].f = ;
return ;
}
push(ls); push(rs);
update(k);
}
void IntSqrt(int k, int ll, int rr) {
if(ll <= T[k].l && T[k].r <= rr) {
if(T[k].f) return ;
push(k); return ;
}
int mid = T[k].l + T[k].r >> ;
if(ll <= mid) IntSqrt(ls, ll, rr);
if(rr > mid) IntSqrt(rs, ll, rr);
update(k);
}
int IntSum(int k, int ll, int rr) {
if(ll <= T[k].l && T[k].r <= rr) return T[k].w;
int mid = T[k].l + T[k].r >> ;
if(ll > mid) return IntSum(rs, ll, rr);
else if(rr <= mid) return IntSum(ls, ll, rr);
else return IntSum(ls, ll, rr) + IntSum(rs, ll, rr);
}
main() {
int tot = ;
while(scanf("%d", &N) != EOF) {
printf("Case #%d:\n", ++tot);
for(int i = ; i <= N; i++) a[i] = read();
Build(, , N);
M = read();
while(M--) {
int k = read(), l = read(), r = read();
if(l > r) swap(l, r);
if(k == ) IntSqrt(, l, r);
else printf("%lld\n", IntSum(, l, r));
}
puts("");
} return ;
}
/* */
SPOJ2713GSS4 - Can you answer these queries IV(线段树)的更多相关文章
- GSS4 2713. Can you answer these queries IV 线段树
GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...
- SP2713 GSS4 - Can you answer these queries IV(线段树)
传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...
- SPOJ GSS1_Can you answer these queries I(线段树区间合并)
SPOJ GSS1_Can you answer these queries I(线段树区间合并) 标签(空格分隔): 线段树区间合并 题目链接 GSS1 - Can you answer these ...
- SPOJ 1557. Can you answer these queries II 线段树
Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/pr ...
- bzoj 2482: [Spoj GSS2] Can you answer these queries II 线段树
2482: [Spoj1557] Can you answer these queries II Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 145 ...
- 【BZOJ2482】[Spoj1557] Can you answer these queries II 线段树
[BZOJ2482][Spoj1557] Can you answer these queries II Description 给定n个元素的序列. 给出m个询问:求l[i]~r[i]的最大子段和( ...
- HDU 4027 Can you answer these queries?(线段树区间开方)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)
Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K ...
- SPOJ GSS3 Can you answer these queries III[线段树]
SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...
随机推荐
- sortable结合angularjs实现拖动排序
记录拖动排序 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Flask&&人工智能AI --2
参考博客: https://www.cnblogs.com/xiao987334176/p/9598606.html 昨日作业讲解 昨天的作业就是,有3个视图函数,分别是/login,/student ...
- Domain Model
VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来. DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的 ...
- FTP服务器windows配置
1.配置IIS Web的FTP站点 1.1 打开iis管理器(方法很多,这里我们用命令) Win+r中输入:inetmgr 1.2 新建FTP站点 1.2.1 新建FTP服务器根目录文件夹 1.2.2 ...
- JAVA内存模型(Java Memory Model ,JMM)
http://blog.csdn.net/hxpjava1/article/details/55189077 JVM有主内存(Main Memory)和工作内存(Working Memory),主内存 ...
- eclipse自动添加版权信息
Preference->Java->Code Style->Code Template->comments->Files->Edit 勾选上Automaticall ...
- Spring Cloud微服务初探
学习初衷 因为加了不少优秀的知识星球,结交了更多的小伙伴,加了更多的群,每每在自我介绍的时候,都说自己是Android & Java攻城狮. 然鹅,有的小伙伴就来问了,你是搞Java的,那对S ...
- JavaScript函数体系
第4章 JavaScript函数 1. 函数基本介绍 ① 为什么需要函数 函数最大的好处就是将零散的代码封装到了一起,当我们要再次使用该功能的时候,不需要再重新书写代码,只需要调用封装好的函数就可以 ...
- <Openssl下hash函数>
hash函数:是不可逆的函数,它的输入可以是任意长度的字节流.它的输出是固定大小的,hash函数的作用就是给你的文件产生一个摘要,它是独一无二的. 例如:y=f(x) x代表输入 y代表输出 输 ...
- using System.Web.Script.Serialization
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...