[传送门](SP2713 GSS4 - Can you answer these queries IV)

解题思路

  大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记。然后每次修改时先看是否有全\(1\)或\(0\)的标记,有就不用理了,没有就暴力开方。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define int long long using namespace std;
const int MAXN = 100005; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?0:1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f?x:-x;
} int n,m,a[MAXN],sum[MAXN<<2],tag[MAXN<<2],lazy[MAXN<<2],cnt; void build(int x,int l,int r){
if(l==r) {
a[l]=rd();sum[x]=a[l];lazy[x]=tag[x]=0;
if(sum[x]==1 || sum[x]==0) lazy[x]=1;
return ;
}
int mid=(l+r)>>1;
build(x<<1,l,mid);build(x<<1|1,mid+1,r);
sum[x]=sum[x<<1]+sum[x<<1|1];
lazy[x]=(lazy[x<<1]&lazy[x<<1|1]);tag[x]=0;
} inline void pushdown(int x,int l,int r){
int mid=(l+r)>>1;
if(!lazy[x<<1]){
tag[x<<1]+=tag[x];lazy[x<<1]=1;sum[x<<1]=0;
for(int i=l;i<=mid;i++){
if(a[i]>1) lazy[x<<1]=0;sum[x<<1]+=a[i];
}
}
if(!lazy[x<<1|1]){
tag[x<<1|1]+=tag[x];lazy[x<<1|1]=0;sum[x<<1|1]=0;
for(int i=mid+1;i<=r;i++){
if(a[i]>1) lazy[x<<1|1]=0;sum[x<<1|1]+=a[i];
}
}
tag[x]=0;
} void update(int x,int l,int r,int L,int R){
if(lazy[x]) return;
if(L<=l && r<=R){
tag[x]++;lazy[x]=1;sum[x]=0;
for(int i=l;i<=r;i++) {
if(a[i]>1) a[i]=sqrt(a[i]);
if(a[i]>1) lazy[x]=0;
sum[x]+=a[i];
}
return ;
}
int mid=(l+r)>>1;if(tag[x]) pushdown(x,l,r);
if(L<=mid) update(x<<1,l,mid,L,R);
if(mid<R) update(x<<1|1,mid+1,r,L,R);
sum[x]=sum[x<<1]+sum[x<<1|1];
lazy[x]|=(lazy[x<<1]&lazy[x<<1|1]);
} int query(int x,int l,int r,int L,int R){
if(L<=l && r<=R) return sum[x];
int ret=0,mid=(l+r)>>1;
if(tag[x]) pushdown(x,l,r);
if(L<=mid) ret+=query(x<<1,l,mid,L,R);
if(mid<R) ret+=query(x<<1|1,mid+1,r,L,R);
return ret;
} signed main(){
while(~scanf("%lld",&n)){cnt++;
printf("Case #%lld:\n",cnt);
build(1,1,n);m=rd();int op,x,y;
while(m--){
op=rd(),x=rd(),y=rd();if(x>y) swap(x,y);
if(!op) update(1,1,n,x,y);
else printf("%lld\n",query(1,1,n,x,y));
}
putchar('\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. GSS4 2713. Can you answer these queries IV 线段树

    GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...

  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. SPOJ2713GSS4 - Can you answer these queries IV(线段树)

    题意 Sol 讲过无数次了..很显然,一个$10^12$的数开方不超过$8$次后就会变为$1$ 因此直接暴力更改即可,维护一下这段区间是否被全改为了$1$ 双倍经验:https://www.luogu ...

  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. GSS4 - Can you answer these queries IV(线段树懒操作)

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

随机推荐

  1. hightchart 报错 Error in mounted hook: "Error: Highcharts error #17: www.highcharts.com/errors/17"

    这个错误是应该导入hightchart 使用的相关的 东西 ,这里是worldcloud import  Wordcloud    from  'highcharts/modules/wordclou ...

  2. 理解 Java 序列化

    一.什么是序列化 序列化是一种对象持久化的手段.类通过实现 java.io.Serializable 接口以启用其序列化功能. 序列化:把对象转换为字节序列的过程. 反序列化:把字节序列恢复为对象的过 ...

  3. Vue 指令大全

    准备开始本章要给大家带来的内容是相关Vue中的组件以及一系列常用属性.本章合适人群囊括了除已有开发经验人员以外的小白新手,从how.why.what三个角度来让大家理解并使用该技术历史介绍angula ...

  4. Mongodb导入本地数据(.dat)到仓库(window)

    借鉴文章,完成了数据文件导入到Mongodb, 尊重作者版权:https://blog.csdn.net/weixin_44198965/article/details/100022616 1.找到你 ...

  5. PHP ftp_connect() 函数

    定义和用法 ftp_connect() 函数打开 FTP 连接. 当连接打开后,您就可以通过服务器来运行 FTP 函数了. 语法 ftp_connect(host,port,timeout) 参数 描 ...

  6. XMPP的总体架构和Jabber ID

    通常XMPP的架构用C/S来实现,但是也并不是强制的,Client和Server,Server和Server之间通过TCP连接来通信. 架构的简单示意图如下: C1-----S1----S2----C ...

  7. 2018ACM-ICPC EC-Final 现场赛I题 Misunderstanding...Missing 倒着DP

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog @ Problem:  很多acm群里有题面PDF了,我就不赘述了.简单说一 ...

  8. 30天轻松学习javaweb_通过javac编译java文件

    通过javac编译java文件1.先导入需要引用的包D:\Program Files (x86)\apache-tomcat-7.0.53\webapps\test\WEB-INF\classes&g ...

  9. php开发面试题---2、php常用面试题二(表单提交方式中的get和post有什么区别)

    php开发面试题---2.php常用面试题二(表单提交方式中的get和post有什么区别) 一.总结 一句话总结: 数据位置:get参数在url里面,post在主体里面 数据大小:get几kb,pos ...

  10. thinkphp ajax调用demo

    http://files.cnblogs.com/files/jxkshu/tp_ckgd.rar