题意

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. POJ 2068 NIm (dp博弈,每个人都有特定的取最大值)

    题目大意: 有2n个人,从0开始编号,按编号奇偶分为两队,循环轮流取一堆有m个石子的石堆,偶数队先手,每个人至少取1个,至多取w[i]个,取走最后一个石子的队伍输.问偶数队是否能赢. 分析: 题目数据 ...

  2. Flask&&人工智能AI --3

    一.flask中的CBV 对比django中的CBV,我们来看一下flask中的CBV怎么实现? from flask import Flask, render_template, url_for, ...

  3. 设计模式——原型模式(Prototype)

    用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象.——DP UML类图 模式说明 如果把在一张纸上手写一篇简历的过程看成是类的实例化过程,那么通过原型模式创建对象的过程就是拿着这张纸到复印 ...

  4. git——解决“fatal: Authentication failed for 'https://github.com/balabala”

    平复一下心情,到底如何在github上将队友和owner的仓库连接?如何push代码到远程仓库???找了巨多教程,终于解决了~ 刚到公司不久,开始学着用git,在提交代码的时候怎么都提不上去! 解决办 ...

  5. 003 Longest Substring Without Repeating Characters 最长不重复子串

    Given a string, find the length of the longest substring without repeating characters.Examples:Given ...

  6. 二维hash

    题目描述 给出一个n * m的矩阵.让你从中发现一个最大的正方形.使得这样子的正方形在矩阵中出现了至少两次.输出最大正方形的边长. 输入描述: 第一行两个整数n, m代表矩阵的长和宽: 接下来n行,每 ...

  7. about 字节

    关于由于赋值导致字节的截断.字节扩展及数据类型的提升: 一.字节截断:int----->char 当一个字节(8位)放不下时,出现截断,直接取(最后一个字节)最后面面8位. 例如:1000000 ...

  8. Java集合——List集合

    1.集合框架的作用 在实际开发中,我们经常会对一组相同类型的数据进行统一管理操作.到目前为止,我们可以使用数组结构,链表结构,二叉树结构来实现. 数组的最大问题在于数组中的元素个数是固定的,要实现动态 ...

  9. asp.net web 开发中配置web.config

    一.配置数据库连接字符串 <connectionStrings> <add name="CaoLPractise" connectionString=" ...

  10. 检查python以及django是否安装配置成功

    首先说明下,我使用pycharm作为开发的IDE,在第一次创建django项目的时候,会自动安装django包的.(网上也有很多单独安装的方法),环境变量配置成功后,就是用下面的方法检测安装成功与否. ...