题意

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(线段树)的更多相关文章

  1. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  2. SP2713 GSS4 - Can you answer these queries IV(线段树)

    传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...

  3. SPOJ GSS1_Can you answer these queries I(线段树区间合并)

    SPOJ GSS1_Can you answer these queries I(线段树区间合并) 标签(空格分隔): 线段树区间合并 题目链接 GSS1 - Can you answer these ...

  4. 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 ...

  5. 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 ...

  6. 【BZOJ2482】[Spoj1557] Can you answer these queries II 线段树

    [BZOJ2482][Spoj1557] Can you answer these queries II Description 给定n个元素的序列. 给出m个询问:求l[i]~r[i]的最大子段和( ...

  7. HDU 4027 Can you answer these queries?(线段树区间开方)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  8. hdu 4027 Can you answer these queries? (区间线段树,区间数开方与求和,经典题目)

    Can you answer these queries? Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65768/65768 K ...

  9. 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 ...

随机推荐

  1. Restful 3 -- 序列化组件(GET/PUT/DELETE接口设计)、视图优化组件

    一.序列化组件 基于上篇随笔的表结构,通过序列化组件的ModelSerializer设计如下三个接口: GET 127.0.0.1:8000/books/{id} # 获取一条数据,返回值:{} PU ...

  2. 07.Spring Bean 加载 - BeanDefinitionReader

    基本概念 BeanDefinitionReader ,该接口的作用就是加载 Bean. 在 Spring 中,Bean 一般来说都在配置文件中定义.而在配置的路径由在 web.xml 中定义.所以加载 ...

  3. Windows进程通信之一看就懂的匿名管道通信

    目录 进程通信之一看就懂的匿名管道通信 一丶匿名管道 1.1何为匿名管道 1.2创建匿名管道需要注意的事项 1.3 创建匿名管道需要的步骤 1.4代码例子 1.5代码运行截图 进程通信之一看就懂的匿名 ...

  4. php面试题分享

    1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hello tush ...

  5. int,long,long long的数据范围

    unsigned   int   0-4294967295   int   2147483648-2147483647 unsigned long 0-4294967295long   2147483 ...

  6. SpringBoot | 第二十章:异步开发之异步请求

    前言 关于web开发的相关知识点,后续有补充时再开续写了.比如webService服务.发邮件等,这些一般上觉得不完全属于web开发方面的,而且目前webService作为一个接口来提供服务的机会应该 ...

  7. Sql server 数据库的备份和还原数据库提示“ 加载的介质已格式化为支持 1 个介质簇,但根据指定的备份设备,应支持 2 个介质簇”

     数据库备份和还原总结 在 "M:\2017-Pro\company\other\databak_2014-10\anquanbaowei_db_201704300200.BAK" ...

  8. ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第十一天(非原创)

    文章大纲 一.课程介绍二.订单系统介绍三.项目源码与资料下载四.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业的背景.淘淘商城的介绍.搭建项目工程.Svn的使用.(2)第二天:框架的整合 ...

  9. 从零开始的全栈工程师——js篇2.13(案例存放:三重数组渲染)

  10. 利用Cookie保存用户身份信息实现免登录

    <%@page import="sun.misc.BASE64Encoder"%> <%@page import="java.util.Base64.E ...