判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(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的更多相关文章
- HDU 5828 Rikka with Sequence (线段树)
Rikka with Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...
- hdu 5828 Rikka with Sequence 线段树
Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...
- HDU 5828 Rikka with Sequence(线段树 开根号)
Rikka with Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5828 Rikka with Sequence(线段树区间加开根求和)
Problem DescriptionAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he g ...
- HDU 5828 Rikka with Sequence (线段树+剪枝优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5828 给你n个数,三种操作.操作1是将l到r之间的数都加上x:操作2是将l到r之间的数都开方:操作3是 ...
- HDU 5828 Rikka with Sequence(线段树)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5828 [题目大意] 给出一个数列,要求支持区间加法,区间开方和区间和查询操作. [题解] 考虑开方 ...
- HDU 5828 Rikka with Sequence
好久没写线段树了,这题作为一个回味.. 第一种操作的话,就是一个延迟标记. 第二种操作可以暴力更新下去,但是有一个优化,如果某区间内所有值都是一样的,或者最大值和最小值相差1,那么到此结束,不要继续往 ...
- hdu 5204 Rikka with sequence 智商不够系列
Rikka with sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...
- 2017 多校5 hdu 6093 Rikka with Number
2017 多校5 Rikka with Number(数学 + 数位dp) 题意: 统计\([L,R]\)内 有多少数字 满足在某个\(d(d>=2)\)进制下是\(d\)的全排列的 \(1 & ...
随机推荐
- Android 在Intent中传递接口
总结:在Activity中不能用intent传递匿名接口,原因如下:Activity A中生成了匿名接口M, 这个接口的引用就在组Activity A中,Activity A会禁止接口M 序列化.因为 ...
- 利用 img 和 script 发送跨域请求
利用img.src可以发送http请求,但是发送http请求不是img.src的真正用意. 同样,用script.src去请求jsonp格式的接口数据也不是script元素的最初设计用途. 但是这些歪 ...
- Maven找不到java编译器的问题
当使用mvn package打包项目的时候,抛出下面这个错误: [ERROR] Unable to locate the Javac Compiler in: D:\jdk\..\lib\tools. ...
- 安卓开发44:解决 INSTALL_FAILED_UID_CHANGED 等问题
apk无法卸载,一般可以下面的方法试一下: 1. 删除/data/app/(filename) 文件夹下的apk包 2. 删除/system/app/(filename) 文件夹下的apk包 3. 将 ...
- java中的toString方法
对于我这种用惯了C++的人来说,突然见到有人写java程序的时候竟然将整数和String类型的变量使用+连接到一起,感到非常奇怪,追究了下原因. 原来所有的java对象都有toString()方法,而 ...
- nodejs初写心得
nodejs安装后如何查看和安装其他工具 网上nodejs的文章已经很多,这里只是写下自己的小小心得,如果能帮到别人当然更好. 安装nodejs这里就不叙述了,直接上nodejs官网下载就好了,初学者 ...
- 5 commands to check memory usage on Linux
Memory Usage On linux, there are commands for almost everything, because the gui might not be always ...
- ie下jquery ajax 80020101错误的解决方法
<script language="javascript"> <!-- function checkAll(name,isCheck){ ...
- C#中结构体的声明
定义: 结构是用户自定义的值类型 代码样式:struct Pair{ public int X, Y; //公有变量名单词的首字母大写(PascalCase规则)}struct Pa ...
- BZOJ_1029_[JSOI2007]_建筑抢修_(贪心+优先队列)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1029 \(n\)个任务需要完成,给出每个任务所需时间\(t_1\)与deadline\(t_2 ...