GSS4 D - Can you answer these queries IV
//给你一个序列,有两种操作:
//1、给定x和y,将区间[x,y]内的数开方
//2、询问区间和
//
// 因为一个longlong类型的数最多开6次方就变成了1,所以对于1操作,我们暴力修改,
//对每个节点标记一个flag,表示当前节点掌控的区间有没有全变成1或0 (数据中有0)
//如果root->flag==1,就return,因为再怎么改也都还是0或1,不变。 //有多组数据 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std; const int N=1e5+; int n,m;
int type,l,r;
struct Tree
{
bool flag;
int l,r,mid;
long long sum;
}tree[N<<]; long long read()
{
char c=getchar();long long num=,f=;
for(;!isdigit(c);c=getchar())
if(c=='-')
f=-;
for(;isdigit(c);c=getchar())
num=num*+c-'';
return num*f;
} void build(int root,int l,int r)
{
tree[root].l=l,tree[root].r=r,tree[root].mid=l+r>>;
if(l==r)
{
scanf("%lld",&tree[root].sum);
tree[root].flag=tree[root].sum<=;
return;
}
build(root<<,l,tree[root].mid);
build(root<<|,tree[root].mid+,r);
tree[root].sum=tree[root<<].sum+tree[root<<|].sum;
tree[root].flag=tree[root<<].flag&&tree[root<<|].flag;
} void modify(int root,int l,int r)
{
if(tree[root].flag)
return;
if(tree[root].l==tree[root].r)
{
tree[root].sum=sqrt(tree[root].sum);
tree[root].flag=tree[root].sum<=;
return;
}
if(l<=tree[root].mid)
modify(root<<,l,r);
if(tree[root].mid<r)
modify(root<<|,l,r);
tree[root].sum=tree[root<<].sum+tree[root<<|].sum;
tree[root].flag=tree[root<<].flag&&tree[root<<|].flag;
} long long query(int root,int l,int r)
{
if(l<=tree[root].l&&tree[root].r<=r)
return tree[root].sum;
long long sum=;
if(l<=tree[root].mid)
sum+=query(root<<,l,r);
if(tree[root].mid<r)
sum+=query(root<<|,l,r);
return sum;
} int main()
{
int tim=;
while(scanf("%d",&n)!=EOF)
{
printf("Case #%d:\n",++tim);
build(,,n);
scanf("%d",&m);
for(int i=;i<=m;++i)
{
// type=read(),l=read(),r=read();
scanf("%d%d%d",&type,&l,&r);
if(l>r)
swap(l,r);
if(type)
printf("%lld\n",query(,l,r));
else
modify(,l,r);
}
puts("");
}
return ;
}
GSS4 D - 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 ...
- GSS4 - Can you answer these queries IV(线段树懒操作)
GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...
- 线段树 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 ...
- GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)
GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...
- SP2713 GSS4 - Can you answer these queries IV(线段树)
传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...
- SPOJ GSS4 Can you answer these queries IV
Time Limit: 500MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description You are g ...
- 【SP2713 GSS4 - Can you answer these queries IV】 题解
题目链接:https://www.luogu.org/problemnew/show/SP2713 真暴力啊. 开方你开就是了,开上6次就都没了. #include <cmath> #in ...
- 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 ...
- SPOJ GSS4 Can you answer these queries IV ——树状数组 并查集
[题目分析] 区间开方+区间求和. 由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可. 这不是BZOJ上上帝造题7分钟嘛 [代码] #include < ...
随机推荐
- Elasticsearch-6.7.0系列(八)开启kibana监控
修改ES配置: 修改elasticsearch.yml,添加如下xpack配置: xpack.security.enabled: true xpack.ml.enabled: true xpack.l ...
- Jmeter+Ant+Jenkins构建接口自动化测试平台(Windows)
一.首先先介绍下我的环境: 1. win10系统 2. ant版本:apache-ant-1.10.1(作用:执行脚本,便于后期的持续集成,下载地址:http://ant.apache.org/bin ...
- C#通用公共类库ZXNetStandardDepot.Common
总结了一下写项目中遇到的各种方法,总结前辈们的经验,生成了该类库,引用net standard类库,支持net core/net framework. 使用方法 1.nuget 搜索 ZXNetSta ...
- [unity]GPU Instance学习
前言我们之前研究过为什么Unity的UI可以合批,是因为使用了相同的材质进行渲染,UI上不同图片渲染是通过把图片打成一张图集后,使用Image组件对顶点填充了不同的UV值实现的.那么有没有什么办法可以 ...
- git下,输入git log 进入log 怎么退出
解决方案: 英文状态下按Q就可以了 ctrl + c (应该是Linux命令中断的意思,很多中断都是这个命令). Paste_Image.png
- RabbitMQ实战场景(一):异步记录用户操作日志
传统的项目开发中业务流程以串行方式,执行了模块1—>模块2–>模块3 而我们知道,这个执行流程其实对于整个程序来讲是有一定的弊端的,主要有几点: (1)整个流程的执行响应等待时间比较长; ...
- ..\USER\stm32f10x.h(428): error: #67: expected a "}" ADC1_2_IRQn = 18, /*!
MDK软件编译,出现如下错误: ..\USER\stm32f10x.h(428): error: #67: expected a "}" ADC1_2_IRQn = 18, /*! ...
- Git-fatal:remote error:You can't push to git://github.com/username/*.git use https:
注意不是git://github.com/cs942651107/TestCode.git 一个:一个@协议不一样,:的不能push 关联远程库git remote add origin git ...
- vi / vim 字符替换详解
:s/idoxu/isTester.com/g 替换当前行所有 idoxu 为 isTester.com :n,$s/idoxu/isTester.com/ #替换第 n 行开始到最后一行中每一行的第 ...
- Random类产生随机数
Random 类作为JAVA中用于产生的随机数 ,new Random(10) :10是种子数. 注意:Random 的一个特点是:相同种子数的Random对象,对应相同次数生成的随机数字是完全相 ...