// 判断相同区间(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. SqlDBHelper常用方法

    /*============================================================= *.net连接数据库常用方法 *Author : dongny,Li * ...

  2. Dictionary<Key,Value>的用法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. VIM树状文件列表NERDTree

    下载和配置 NERDTree插件的官方地址如下,可以从这里获取最新的版本 https://github.com/scrooloose/nerdtree 下载zip安装包 或者使用下面官网源文件安装方法 ...

  4. Linux 删除文件夹和创建文件的命令

    删除文件夹实例:rm -rf /var/log/httpd/access将会删除/var/log/httpd/access目录以及其下所有文件.文件夹 删除文件使用实例: rm -f /var/log ...

  5. LTDFZ

    开关稳压器

  6. 将SQLServer2005中的数据同步到Oracle中

    有时由于项目开发的需要,必须将SQLServer2005中的某些表同步到Oracle数据库中,由其他其他系统来读取这些数据.不同数据库类型之间的数据同步我们可以使用链接服务器和SQLAgent来实现. ...

  7. Android开发之EventBus的简单使用

    参考: 1.http://blog.csdn.net/harvic880925/article/details/40660137 2.http://blog.csdn.net/harvic880925 ...

  8. Jenkins iOS – Git, xcodebuild, TestFlight

    Introduction with Jenkins iOS If you are new to continuous integration for mobile platforms then you ...

  9. 类Item_equal

    class Item_equal: public Item_bool_func { List<Item_field> fields; /* list of equal field item ...

  10. 【笨嘴拙舌WINDOWS】伟大的变革

    "改革"."革命"."变革" 这几个词语毫无疑问是每一个时代必须被呼吁的词语,当一个国家没有人求变时,那是一个时代的悲剧.无论是文景之治,贞 ...