用计算器算一算,就可以发现\(10^{18}\)的数,被开方\(6\)次后就变为了\(1\)。

所以我们可以直接暴力的进行区间修改,若这个数已经到达\(1\),则以后就不再修改(因为\(1\)开方后还是\(1\)),用并查集和树状数组进行维护。

这个方法用了P2391 白雪皑皑的思想处理,用并查集标记该点已经不再用替换。

和我这题CF920F【SUM和REPLACE】的方法相同。

\(code\):

#include<bits/stdc++.h>
#define maxn 500010
#define lowbit(x) (x&(-x))
typedef long long ll;
using namespace std;
ll n,m;
ll fa[maxn],k,l,r;
ll a[maxn],tree[maxn];
int cnt;
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
void add(int x,ll d)
{
while(x<=n)
{
tree[x]+=d;
x+=lowbit(x);
}
}
ll query(int x)
{
ll sum=0;
while(x)
{
sum+=tree[x];
x-=lowbit(x);
}
return sum;
}
int main()
{
while(scanf("%lld",&n)!=EOF)
{
cnt++;
printf("Case #%d:\n",cnt);
for(int i=1;i<=n*4;++i)
tree[i]=0;
for(int i=1;i<=n;++i)
{
scanf("%lld",&a[i]);
add(i,a[i]);
fa[i]=i;
}
fa[n+1]=n+1;
scanf("%lld",&m);
while(m--)
{
scanf("%lld%lld%lld",&k,&l,&r);
if(l>r)
swap(l,r);
if(k==0)
{
for(int i=l;i<=r;)
{
add(i,(ll)sqrt(a[i])-a[i]);//手动暴力开方
a[i]=(ll)sqrt(a[i]);
if(a[i]<=1)
fa[i]=i+1;//若这个数已经为1,则将其指向它下一个数
if(i==find(i))
i++;
else
i=fa[i];//进行跳转,忽略不再需要开方的数
}
}
else
printf("%lld\n",query(r)-query(l-1));
}
printf("\n");
}
return 0;
}

题解 SP2713 【GSS4 - Can you answer these queries IV】的更多相关文章

  1. 线段树 SP2713 GSS4 - Can you answer these queries IV暨 【洛谷P4145】 上帝造题的七分钟2 / 花神游历各国

    SP2713 GSS4 - Can you answer these queries IV 「题意」: n 个数,每个数在\(10^{18}\) 范围内. 现在有「两种」操作 0 x y把区间\([x ...

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

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

  3. 【SP2713 GSS4 - Can you answer these queries IV】 题解

    题目链接:https://www.luogu.org/problemnew/show/SP2713 真暴力啊. 开方你开就是了,开上6次就都没了. #include <cmath> #in ...

  4. SP2713 GSS4 - Can you answer these queries IV

    题目大意 \(n\) 个数,和在\(10^{18}\)范围内. 也就是\(\sum~a_i~\leq~10^{18}\) 现在有两种操作 0 x y 把区间[x,y]内的每个数开方,下取整 1 x y ...

  5. SP2713 GSS4 - Can you answer these queries IV 分块

    问题描述 LG-SP2713 题解 分块,区间开根. 如果一块的最大值是 \(1\) ,那么这个块就不用开根了. 如果最大值不是 \(1\) ,直接暴力开就好了. \(\mathrm{Code}\) ...

  6. 洛谷P4145 上帝造题的七分钟2 / 花神游历各国(重题:洛谷SP2713 GSS4 - Can you answer these queries IV)

    题目背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 题目描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段 ...

  7. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  8. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  9. 题解【SP2713】GSS4 - Can you answer these queries IV

    题目描述 You are given a sequence \(A\) of \(N(N \leq 100,000)\) positive integers. There sum will be le ...

随机推荐

  1. 一分钟开始持续集成之旅系列之:C 语言 + Makefile

    作者:CODING - 朱增辉 前言 make 工具非常强大,配合 makefile 文件可以实现软件的自动化构建,但是执行 make 命令依然需要经历手动输入执行.等待编译完成.将目标文件转移到合适 ...

  2. git 如何解决 (master|MERGING)

    git 如何解决 (master|MERGING) git reset --hard head //回退版本信息 git pull origin master

  3. spring boot 和shiro的代码实战demo

    spring boot和shiro的代码实战 首先说明一下,这里不是基础教程,需要有一定的shiro知识,随便百度一下,都能找到很多的博客叫你基础,所以这里我只给出代码. 官方文档:http://sh ...

  4. day17—max, map, reduce, filter, zip 函数的使用

    一.max 函数 l=[3,2,100,999,213,1111,31121,333] print(max(l)) # dic={'k1':10,'k2':100,'k3':30} print(max ...

  5. WSL配置高翔vslam环境配置流水账

    1 安装参考博文链接:https://www.cnblogs.com/dalaska/p/12802384.html 2 Ubuntu 16.04地址:https://www.microsoft.co ...

  6. 写出Python中列表、元祖、字典、字符串的至少5种以上的方法

    1.列表 常用方法 作用 参数 append(data) 在尾部添加数据 data-加入到列表中的数据 insert(idx,data) 在指定位置添加数据 idx-索引    data-数据 ext ...

  7. 本地连接虚拟机db2V10.5遇到的问题

    在连接虚拟机数据库时发现自己不知道db2的端口号是多少,百度上说50000,60000的都有,所以还是决定自己试一下,并记录下这个过程 # 首先切换到db2inst1的用户 su - db2inst1 ...

  8. 嘿,java打怪升级攻略

    Java成神之路 第一层 java基础 **当你通过本层所有关卡,你可以完成一些简单的管理系统.坦克大战游戏.QQ通信等. ** 第二层 数据库 数据库类型很多例如:MySQL.oracle.redi ...

  9. C++中string转换为char*类型返回后乱码问题

    问题来源: 在写二叉树序列化与反序列化时发现序列化函数为char* Serialize1(TreeNode *root)  其函数返回类型为char*,但是我在实现的过程中为了更方便的操作添加字符串使 ...

  10. windows jenkins下配置sonar-scanner

    windows jenkins下配置sonar-scanner 一.基本配置信息 ① jenkins版本:2.222.4 ② sonarqube scanner版本:4.4.0.2170 ③ 操作系统 ...