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 < ...
随机推荐
- Badboy与Jmeter脚本录制
下载地址: http://www.badboy.com.au Badboy 是一个强大的工具,旨在帮助测试和开发复杂的动态应用,Badboy 包括一个简单而全面的捕获/回放界面,强大的 ...
- VBA 打印及破密
Sub 打印()ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=TrueCall dyEnd SubSub dy()Dim a%, b ...
- Tomcat启动时一闪而过,看不多错误信息解决方案
转自:https://wangxh89.iteye.com/blog/1824806 有时Tomcat的启动窗口一闪而过,根本就看不出启动过程中发生了什么错误.这中间的原因有好多种,最常见的解决办法就 ...
- python下调用c语言代码
1)首先,创建一个.c文件,其大体内容如下: 2 #include <Python.h> 99 char * extract(char * path) ...
- Android JSBridge原理与实现
在Android中,JSBridge已经不是什么新鲜的事物了,各家的实现方式也略有差异.大多数人都知道WebView存在一个漏洞,详细信息见你不知道的 Android WebView 使用漏洞,虽然该 ...
- org.apache.shiro.session.UnknownSessionException: There is no session with id [xxxx]的解决方案
org.apache.shiro.session.UnknownSessionException: There is no session with id [xxxx]的解决方案 背景描述 Sprin ...
- Android自动化测试探索(二)常用自动化工具
Android常用自动化工具 ADB - 是Google提供的为Android编写UI测试用例的自动化工具, Android开发/测试人员不可替代的强大工具 uiautomator - 是Google ...
- 使用BERT模型生成token级向量
本文默认读者有一定的Transformer基础,如果没有,请先稍作学习Transormer以及BERT. 相信网上有很多方法可以生成BERT向量,最有代表性的一个就是bert as service,用 ...
- 云计算/云存储---Ceph和Openstack的cinder模块对接方法
1.创建存储池 在ceph节点中执行如下语句. #ceph osd pool create volumes 2.配置 OPENSTACK 的 CEPH 客户端 在ceph节点两次执行如下语句,两次{y ...
- PAT1125
总体思路 这道题就是一道贪心题. 对我来说,这道题的关键在于他在说什么(黑人问号???),一开始读了几遍都不知道在讲什么,怎么一根绳子对折后就和另一根套上了? 描述上面确实让人比较迷糊,配图也不是很明 ...