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 ...
随机推荐
- spring静态工厂方法得到单例bean
import org.springframework.beans.BeansException; import org.springframework.context.ApplicationConte ...
- 【ACM】取石子 - 博弈论
取石子(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游 ...
- 024 Swap Nodes in Pairs 交换相邻结点
给定一个链表,对每两个相邻的结点作交换并返回头节点.例如:给定 1->2->3->4,你应该返回 2->1->4->3.你的算法应该只使用额外的常数空间.不要修改列 ...
- SQL判断经纬度在矩形内
1,将城市地图拆分等距拆分为矩形 数据结构如图: 2.查看高德JS API (点是否在多边形内)核心代码: a=[114.069564,22.545774]; b=[ [114.067595,22.5 ...
- MySQL导入大sql 文件大小限制问题的解决
解决过程如下: 1.由于mysql能解析sql的压缩文件,因此将200M压缩后为5M. 2.默认情况下:MySQL导入文件大小有限制的,最大为2M,所以当文件很大时候,直接无法导入,可修改php.in ...
- cucumber的hooks
引用链接:https://github.com/cucumber/cucumber/wiki/Hooks Hooks Cucumber provides a number of hooks which ...
- 【转】c# winform 创建文件,把值写入文件,读取文件里的值,修改文件的值,对文件的创建,写入,修改
创建文件和读取文件的值 #region 判断文件是否存在,不存在则创建,否则读取值显示到窗体 public FormMain() { InitializeComponent(); //ReadFile ...
- X64下IIS调用32位的dll
WebAPI项目中遇到了需要调用32位C++的dll的情况,调试的时候能正常调用,但是发布了之后部署在IIS中出现了BadFormatImage异常, 解决方法是在IIS中相应应用程序池=>高级 ...
- Laravel项目的结构文章
http://esbenp.github.io/2016/04/11/modern-rest-api-laravel-part-1/
- 安卓adb调试命令常见的问题
首先本人使用的是ubuntu系统,在Eclipse下开发的时候使用无线调试,在终端直接输入adb connect 114.114.114.114没有问题,给手机安装软件用adb install ** ...