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 ...
随机推荐
- Leetcode初级算法(字符串篇)
目录 反转字符串 颠倒整数 字符串中的第一个唯一字符 有效的字母异位词 验证回文字符串 实现strStr() 数数并说 最长公共前缀 字符串转整数(atoi) 反转字符串 和vector同样的进行sw ...
- redis结合springboot 无法注入redisTemplate问题
报错: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean o ...
- 【ACM】孪生素数问题
孪生素数问题 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 写一个程序,找出给出素数范围内的所有孪生素数的组数.一般来说,孪生素数就是指两个素数距离为2,近的不能再 ...
- ubuntu查看系统版本和内核版本
查看系统版本: cat /etc/issue sudo lsb_release -a 查看内核版本: uname -r
- hdu2069(Coin Change)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Coin Change Time Limit: 1000/1000 MS (Java/Other ...
- 浅谈堆-Heap(一)
应用场景和前置知识复习 堆排序 排序我们都很熟悉,如冒泡排序.选择排序.希尔排序.归并排序.快速排序等,其实堆也可以用来排序,严格来说这里所说的堆是一种数据结构,排序只是它的应用场景之一 Top N的 ...
- Docker for mac 安装 kong
首先安装一个 PostgreSQL,选的版本是 9.5 $ docker run -d --name kong-database \ -p : \ -e "POSTGRES_USER=kon ...
- UICollectionView基础API笔记
UICollectionView系列API,属性含义笔记.在UICollectionView笔记1中我们了解了UICollectionView是什么,以及可以做什么:在UICollectionView ...
- 关于myeclipse导入项目时出现的中文注释乱码问题
要设置myeclipse的编码,需要了解各个设置项的作用 第一类编码设置项,虽然有三处设置,但是是可以归为一类的 第一处为myeclipse的工作区(workspace),其范围最 ...
- 如何从MYSQL官方YUM仓库安装MYSQL5.x 原理一样只要获取对的仓库依赖安装对的仓库依赖就ok了,我就是用这种安装的5.7
如何从MYSQL官方YUM仓库安装MYSQL5.6 2013年10月,MySQL开发团队正式宣布支持Yum仓库,这就意味着我们现在可以从这个Yum库中获得最新和最优版的MySQL安装包.本文将在一台全 ...