//给你一个序列,有两种操作:
//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的更多相关文章

  1. GSS4 2713. Can you answer these queries IV 线段树

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

  2. GSS4 - Can you answer these queries IV(线段树懒操作)

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

  3. 线段树 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 ...

  4. GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)

    GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...

  5. SP2713 GSS4 - Can you answer these queries IV(线段树)

    传送门 解题思路 大概就是一个数很少次数的开方会开到\(1\),而\(1\)开方还是\(1\),所以维护一个和,维护一个开方标记,维护一个区间是否全部为\(1/0\)的标记.然后每次修改时先看是否有全 ...

  6. SPOJ GSS4 Can you answer these queries IV

    Time Limit: 500MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Description You are g ...

  7. 【SP2713 GSS4 - Can you answer these queries IV】 题解

    题目链接:https://www.luogu.org/problemnew/show/SP2713 真暴力啊. 开方你开就是了,开上6次就都没了. #include <cmath> #in ...

  8. 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 ...

  9. SPOJ GSS4 Can you answer these queries IV ——树状数组 并查集

    [题目分析] 区间开方+区间求和. 由于区间开方次数较少,直接并查集维护下一个不是1的数的位置,然后暴力修改,树状数组求和即可. 这不是BZOJ上上帝造题7分钟嘛 [代码] #include < ...

随机推荐

  1. go 学习笔记(3) 基础结构

    package main import ( "fmt" ) const NAME string = "imooc" var a string = "慕 ...

  2. 物流管理系统(SSM+vue+shiro)【前后台】

    一.简单介绍项目 该项目是属于毕业设计项目之一,有前台的用户下单.有司机进行接单.有管理员进行操作后台,直接进入主题 毕设.定制开发 联系QQ:761273133 登录主页: 手机号码+验证码登录 或 ...

  3. Java 处理异常

    Java中 ,catch块和 finally块中都有可能发生异常,这时候就需要 用throw 抛出异常       类似于 C#里方法体中的 throw:

  4. centos下安装nginx(转载)

    http://blog.csdn.net/u010246789/article/details/51501710 有声明,不能转载,所以,就把地址弄了过来

  5. css设置全局变量和局部变量

    在我们使用less或者sass时常常会使用到局部变量和全局变量,其实在我们使用css做开发时也可以定义全局变量和局部 变量来简化我们的开发效率,很简单也很实用:1.设置全局变量只需要在我们的根引用的c ...

  6. Winform开发1

    VS的Winform开发中,TextBox可能拖过来的时候不能改变其高度,这就要在其属性Multiline为True.

  7. 判断是否发生url跳转

    url="https://www.baidu.com/" url='http://www.freebuf.com/fevents/133225.html' # 方法一:禁止跳转:a ...

  8. Android笔记(五十五) Android四大组件之一——ContentProvider,使用系统提供的ContentProvider

    因为在Android中,存储系统联系人姓名和电话是存在与不同的ContentProvider中的,具体如何查找,可以从Android的源代码中查看,在android.providers包中列出了所有系 ...

  9. HashMap,HashSet

    HashMap,HashSet 摘自:https://www.cnblogs.com/skywang12345/p/3310887.html#a1 目录 一.    HashMap(键值对形式存取,键 ...

  10. centos6/7添加系统服务

    服务脚本必须存放在/etc/ini.d/目录下:       chkconfig --add mongodb     chkconfig --list mongodb     等级0表示:表示关机   ...