// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 题意:三种操作,1增加值,2开根,3求和
// 思路:这题与HDU 4027 和HDU 5634 差不多
// 注意开根号的话,遇到极差等于1的,开根号以后有可能还是差1.如
// 2 3 2 3。。。
// 8 9 8 9。。。
// 2 3 2 3。。。
// 8 9 8 9。。。
// 剩下就是遇到区间相等的话,就直接开根号不往下传 #include <bits/stdc++.h>
using namespace std;
#define LL long long
const int inf = 0x3f3f3f3f;
const int MOD =;
const int N =1e5+;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre(){freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;}
int n,q;
int a[N];
struct node{
int l,r,len;
LL sum,lazy;
LL mx,mn;
}t[N<<]; void pushup(int rt){
t[rt].sum=t[rt<<].sum+t[rt<<|].sum;
t[rt].mx=max(t[rt<<].mx,t[rt<<|].mx);
t[rt].mn=min(t[rt<<|].mn,t[rt<<].mn);
}
void pushdown(int rt){
if(t[rt].lazy){
t[rt<<].lazy+=t[rt].lazy;
t[rt<<].mx+=t[rt].lazy;
t[rt<<].mn+=t[rt].lazy;
t[rt<<].sum+=t[rt<<].len*t[rt].lazy;
t[rt<<|].lazy+=t[rt].lazy;
t[rt<<|].mx+=t[rt].lazy;
t[rt<<|].mn+=t[rt].lazy;
t[rt<<|].sum+=t[rt<<|].len*t[rt].lazy;
t[rt].lazy=;
}
}
void build(int rt,int l,int r){
t[rt].l=l;
t[rt].r=r;
t[rt].lazy=;
t[rt].mx=;
t[rt].mn=inf;
t[rt].len=r-l+;
if(l==r){
t[rt].sum=a[l],t[rt].mx=t[rt].mn=a[l];
return;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
pushup(rt);
} void update1(int rt,int l,int r,int z){
if(t[rt].l>=l&&t[rt].r<=r){
t[rt].sum+=(LL)t[rt].len*z;
t[rt].lazy+=z;
t[rt].mn+=z;
t[rt].mx+=z;
return;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(r<=mid) update1(rt<<,l,r,z);
else if(l>mid) update1(rt<<|,l,r,z);
else {
update1(rt<<,l,mid,z);
update1(rt<<|,mid+,r,z);
}
pushup(rt);
} void update2(int rt,int l,int r){
if(t[rt].l>=l&&t[rt].r<=r){
if(t[rt].mx==t[rt].mn){
LL tem=(LL)sqrt(t[rt].mx);
t[rt].sum=(LL)tem*t[rt].len;
t[rt].lazy-=(t[rt].mx-tem);
t[rt].mx=t[rt].mn=tem;
return;
}
else if(t[rt].mx==t[rt].mn+){
LL tem1=(LL)sqrt(t[rt].mx);
LL tem2=(LL)sqrt(t[rt].mn);
if(tem1==tem2+){
t[rt].sum-=(LL)(t[rt].mx-tem1)*t[rt].len;
t[rt].lazy-=(t[rt].mx-tem1);
t[rt].mx=tem1;
t[rt].mn=tem2;
return;
}
}
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(r<=mid) update2(rt<<,l,r);
else if(l>mid) update2(rt<<|,l,r);
else {
update2(rt<<,l,mid);
update2(rt<<|,mid+,r);
}
pushup(rt);
} LL query(int rt,int l,int r){
if(t[rt].l>=l&&t[rt].r<=r){
return t[rt].sum;
}
pushdown(rt);
int mid=(t[rt].l+t[rt].r)>>;
if(r<=mid) return query(rt<<,l,r);
else if(l>mid) return query(rt<<|,l,r);
else {
return query(rt<<,l,mid)+query(rt<<|,mid+,r);
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++) {
scanf("%d",&a[i]);
}
build(,,n);
while(q--){
int op,x,y,z;
scanf("%d%d%d",&op,&x,&y);
if(op==){
scanf("%d",&z);
update1(,x,y,z);
}
else if(op==){
update2(,x,y);
}
else {
LL ans=query(,x,y);
printf("%I64d\n",ans);
}
}
}
return ;
}

判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence的更多相关文章

  1. HDU 5828 Rikka with Sequence (线段树)

    Rikka with Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...

  2. hdu 5828 Rikka with Sequence 线段树

    Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...

  3. HDU 5828 Rikka with Sequence(线段树 开根号)

    Rikka with Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. HDU 5828 Rikka with Sequence(线段树区间加开根求和)

    Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he g ...

  5. HDU 5828 Rikka with Sequence (线段树+剪枝优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,三种操作.操作1是将l到r之间的数都加上x:操作2是将l到r之间的数都开方:操作3是 ...

  6. HDU 5828 Rikka with Sequence(线段树)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5828 [题目大意] 给出一个数列,要求支持区间加法,区间开方和区间和查询操作. [题解] 考虑开方 ...

  7. HDU 5828 Rikka with Sequence

    好久没写线段树了,这题作为一个回味.. 第一种操作的话,就是一个延迟标记. 第二种操作可以暴力更新下去,但是有一个优化,如果某区间内所有值都是一样的,或者最大值和最小值相差1,那么到此结束,不要继续往 ...

  8. hdu 5204 Rikka with sequence 智商不够系列

    Rikka with sequence Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  9. 2017 多校5 hdu 6093 Rikka with Number

    2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...

随机推荐

  1. java中什么时候该用static修饰方法?有什么好处或者坏处?

    当一个方法或者变量需要初始化加载,或者是经常被调用的时候可以加上static.用static修饰的方法可以用类名直接调用,不用的一定要先实例化一个对象然后才可以调用比如 person这个类里面有一个方 ...

  2. linux服务器下发送邮件

    系统管理人员经常会遇到对于设备或者任务的预警与通知,通常情况有发送短信.邮件等方式.发送短信一般来说需要有短信猫(硬件)或者调用libfetion给飞信用户发送.本文介绍几种简单的发送邮件的方式. 本 ...

  3. python各种类型转换-int,str,char,float,ord,hex,oct等

    int(x [,base ])         将x转换为一个整数  long(x [,base ])        将x转换为一个长整数  float(x )               将x转换到 ...

  4. OSSEC配置文件ossec.conf中添加mysql服务

    配置路径:/opt/ossec/etc/ossec.conf <ossec_config>   <global>     <email_notification>y ...

  5. mysqldump常用于MySQL数据库逻辑备份

    mysqldump常用于MySQL数据库逻辑备份. 1.各种用法说明 A. 最简单的用法: mysqldump -uroot -pPassword [database name] > [dump ...

  6. mysql: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x90</...'

    插入数据出现问题,因为包含了特殊字符. 现象: 插入的数据中如果含有某些特殊字符,会导致插入数据失败,例如字符串”测试**插入数据...“,在console中insert是正常的,但是使用java代码 ...

  7. MATLAB曲线绘制

    一. 二维数据曲线图1.1 绘制 单根二维曲线plot 函数的基本调用 格式为:plot(x,y) 其中x和y为长度相同的向量,分别用于存储x坐标 和y坐标数据. 例1-1 在0≤x≤2p区间内,绘制 ...

  8. 分布式ActiveMQ集群

    分布式ActiveMQ集群的部署配置细节: 官方资料:http://activemq.apache.org/clustering.html 基本上看这个就足够了,本文就不具体分析配置文件了. 1.Qu ...

  9. linux scp

    scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令.linux的scp命令可以在linux服务器之间复制文件和目录. scp命令的用处: scp ...

  10. shell/bash 让vi/vim显示空格,及tab字符

    shell/bash 让vi/vim显示空格,及tab字符 Vim 可以用高亮显示空格和TAB.文件中有 TAB 键的时候,你是看不见的.要把它显示出来::set listTAB 键显示为 ^I,   ...