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 < ...
随机推荐
- Centos 6.10 安装 Jenkins
前言 持续集成的概念 持续集成,Continuous integration ,简称CI. 持续集成正是针对这一类问题的一种软件开发实践.它倡导团队开发成员必须经常集成他们的工作,甚至每天都可能发生多 ...
- Navicat premium工具转储数据表的结构时,datatime字段报错
Navicat premium工具导出数据库: Navicat premium工具导入数据库: 运行SQL文件,遇到的错误,红色下划线提示,发现:(SQL文件的时间有问题) 不是insert语句有问题 ...
- Oracle 11g安装过程工作Oracle数据库安装图解
一.Oracle 下载 注意Oracle分成两个文件,下载完后,将两个文件解压到同一目录下即可. 路径名称中,最好不要出现中文,也不要出现空格等不规则字符. 官方下地址: oracle.com/tec ...
- js 简单的滑动1
js 简单的滑动教程(一) 作者:Lellansin 转载请标明出处,谢谢 首先我们要实现一个简单的滑动,三张图.点击左边向左滑动,点右向右滑,碰到临界值的时候就不能滑动. 这个简单滑动的原理是, ...
- Postman请求后台报错:Invalid character found in method name. HTTP method names must be tokens
在使用Postman请求后台时Postman出现 开发工具控制台报 信息: Error parsing HTTP request header Note: further occurrences of ...
- Android 常用开源库总结(持续更新)
前言 收集了一些比较常见的开源库,特此记录(已收录350+).另外,本文将持续更新,大家有关于Android 优秀的开源库,也可以在下面留言. 一 .基本控件 TextView HTextView 一 ...
- 谈一谈做iOS播放器库开发所涉及的知识点
在自己研究生毕业的时候,想着能找上一份做视频编解码的工作,可惜没有如愿,最后到了一家iOS游戏渠道公司去做游戏支付业务的SDK开发,我的iOS正式开发生涯就这么开始了. 在那家iOS游戏渠道没做上一年 ...
- Python学习日记(七) 文件操作
文件操作: 首先要有一个文件作为对象,例‘文件名’.txt 1.文件路径:例 d:\文件名.txt <1>:绝对路径:从根目录往后的路径 <2>:相对路径:当前目录下的路径有什 ...
- 【转】如何使用jupyter编写数学公式(译)
[1.如何使用jupyter编写数学公式(译)][1] [1]: https://www.jianshu.com/p/93ccc63e5a1b
- Deep learning_CNN_Review:A Survey of the Recent Architectures of Deep Convolutional Neural Networks——2019
CNN综述文章 的翻译 [2019 CVPR] A Survey of the Recent Architectures of Deep Convolutional Neural Networks 翻 ...