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 < ...
随机推荐
- (二)Django自定义标签
1.创建自定义标签 在项目的APP中新建一个Python Package-->blog_tags.py 代码: from django import template from ..models ...
- Autofac在.NetCore 下的使用
在工作开发中很多地方都会使用到接口模式开发,这里就会用到依赖注入,.NetCore目前是自带的 ,在 Startup.cs中的 ConfigureServices方法中增加 public void C ...
- devextreme组装数据导出excel
$.get("", function (grid_dataSource) { var grid_config = dxConfig.grid(grid_dataSource); g ...
- Oracle.EntityFrameworkCore使用时报错:ORA-00933:SQL命令未正确结束
如果你在使用 Oracle.EntityFrameworkCore 在执行一些分页查询或者其他数据操作时,遇到“ORA-00933:SQL命令未正确结束”, 请先检查你的DbContext中UseOr ...
- WebClient 请求 https 页面出错:未能创建 SSL/TLS 安全通道
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | Securi ...
- 进入恢复模式(Recovery HD)
进入恢复模式(Recovery HD) 1,选中要启动的虚拟机,随后点击VM菜单的启动按钮后面向下箭头,随后点击菜单项”打开电源时进入固件“. 2,在虚拟机里面,用上下键移动到”Enter setup ...
- BUAA_OO第四单元总结性博客作业——UML(Floyd实现规则检查?)
一.架构设计 1.UML第一次作业——类图 第一次作业基于不同element在UML规格中的从属关系来设计架构.继承了UmlInteraction接口的MyUmlInteraction类是主要的交互层 ...
- text-overflow 全兼容
text-overflow 全兼容 text-overflow 这个CSS属性用于设置或检索是否使用一个省略标记(...)标示对象内文本的溢出.比起在后台用程序截断文本再附上省略标记的做法,用CSS来 ...
- ActiveMQ 认证与授权
使用ActiveMQ自带simpleAuthenticationPlugin 1.直接将用户名密码写入activemq.xml文件 <plugins> <simpleAuthenti ...
- 【hadoop】看懂WordCount例子
前言:今天刚开始看到map和reduce类里面的内容时,说实话一片迷茫,who are you?,最后实在没办法,上B站看别人的解说视频,再加上自己去网上查java的包的解释,终于把WordCount ...