判断相同区间(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 & ...
随机推荐
- C语言的字符测试函数
C语言的字符测试函数 isalnum, isalpha, isdigit, isxdigit, isblank, isspace, isascii, iscntrl, ispunct, isgraph ...
- Java学习笔记之:Java 接口
一.引言 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类 ...
- C#四种文件流的区别(转)
1.FileStream类的读写操作 FileStream类可以对任意类型的文件进行读取操作,而且我们也可以按照需要指定每一次读取字节长度,以此减少内存的消耗,提高读取效率. 代码实例: //创建文件 ...
- CentOS 7.0安装Nvidia驱动
entOS 7.0 Nvidia显卡安装步骤: 1 在英伟达官网下载相应驱动 搜索出相应的驱动后,不要直接点,而是右健,Save Link as... 否则,会出现下载半天没动静的情况. 存放的路径上 ...
- HDU5087——Revenge of LIS II(BestCoder Round #16)
Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...
- 源代码Log
MVC5源代码 https://github.com/aspnet/Mvc MVC4源代码 http://aspnetwebstack.codeplex.com/
- SAP 物料基本单位与BOM单位
比如:物料的基本单位是G,可该物料放到BOM中的单位却是PC,该如何实现呢? 1. 首先要弄清楚BOM单位优先取的是发货单位(工厂数据视图1),当发货单位为空时,取基本单位: 2. 然后再建立单位G ...
- 无法生成临时类(result=1)。 error CS0229: “DCSoftDotfuscate.aam.a”与“DCSoftDotfuscate.aam.a()”之间存在二义性
对于错误无法生成临时类(result=1).error CS0229: “DCSoftDotfuscate.aam.a”与“DCSoftDotfuscate.aam.a()”之间存在二义性 出现这个错 ...
- DataGridView控件的使用---添加行
最简单的方法 可以静态绑定数据源,这样就自动为DataGridView控件添加相应的行. 假如需要动态为DataGridView控件添加新行,方法有很多种,下面简单介绍如何为DataGridView控 ...
- MySQL增加列,移动列
ALTER TABLE test ADD COLUMN id INT UNSIGNED NOT NULL auto_increment PRIMARY KEY FIRST 给表添加列是一个常用的操作, ...