[HDU] 5306 Gorgeous Sequence [区间取min&求和&求max]
题解:
线段树维护区间取min求和求max
维护最小值以及个数,次小值
标记清除时,分情况讨论
当lazy>max1 退出
当max1>lazy>max2(注意不要有等号) 更新
否则递归处理
据吉如一的论文上说是nlogn的复杂度(至今不知论文在何处)
卡常?? 不懂常熟技巧 那就开个o2水一下。。。。
这数的大小 正好2^31 刚开始没看。。对拍挺对交上去wa了
#pragma G++ optimize (2)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1100000
#define INF 2147483647
#define il inline
struct re{
int max1,max2,num,h,t,lazy;
ll sum;
}p[N*];
ll b[N];
int T,n,m;
il void updata(int x)
{
p[x].sum=p[x*].sum+p[x*+].sum;
p[x].max1=max(p[x*].max1,p[x*+].max1);
if (p[x*].max1==p[x*+].max1)
{
p[x].num=p[x*].num+p[x*+].num;
p[x].max2=max(p[x*].max2,p[x*+].max2);
} else
{
re xx=p[x*],yy=p[x*+];
if (xx.max1<yy.max1) swap(xx,yy);
p[x].num=xx.num;
p[x].max2=max(xx.max2,yy.max1);
}
}
#define mid (h+t)/2
void build(int x,int h,int t)
{
p[x].h=h; p[x].t=t; p[x].lazy=INF;
if (h==t)
{
p[x].max1=b[h],p[x].max2=-INF,p[x].num=;
p[x].sum=b[h];
return;
}
build(x*,h,mid); build(x*+,mid+,t);
updata(x);
}
void down(int x)
{
if (p[x].max1<=p[x].lazy) p[x].lazy=INF;
if (p[x].lazy==INF) return;
if (p[x].h!=p[x].t)
{
if (p[x].lazy<p[x*].lazy) p[x*].lazy=p[x].lazy;
if (p[x].lazy<p[x*+].lazy) p[x*+].lazy=p[x].lazy;
}
if (p[x].max1>p[x].lazy&&p[x].max2<p[x].lazy)
{
p[x].sum=p[x].sum-1ll*(p[x].max1-p[x].lazy)*p[x].num;
p[x].max1=p[x].lazy;
} else
{
down(x*); down(x*+);
updata(x);
}
p[x].lazy=INF;
}
void change(int x,int h,int t,int w)
{
down(x);
if (p[x].h>t||p[x].t<h) return;
if (h<=p[x].h&&p[x].t<=t)
{
p[x].lazy=min(p[x].lazy,w); down(x); return;
}
change(x*,h,t,w); change(x*+,h,t,w);
updata(x);
}
int query1(int x,int h,int t)
{
down(x);
if (p[x].h>t||p[x].t<h) return(-INF);
if (h<=p[x].h&&p[x].t<=t) return(p[x].max1);
return(max(query1(x*,h,t),query1(x*+,h,t)));
}
ll query2(int x,int h,int t)
{
down(x);
if (p[x].h>t||p[x].t<h) return();
if (h<=p[x].h&&p[x].t<=t) return(p[x].sum);
return(query2(x*,h,t)+query2(x*+,h,t));
}
int main()
{
freopen("noip.in","r",stdin);
freopen("noip.out","w",stdout);
std::ios::sync_with_stdio(false);
cin>>T;
for (int ttt=;ttt<=T;ttt++)
{
// clear();
cin>>n>>m;
for (int i=;i<=n;i++) cin>>b[i];
build(,,n);
for (int i=;i<=m;i++)
{
int x,y,z,w;
cin>>x;
if (x==)
{
cin>>y>>z>>w;
change(,y,z,w);
}
if (x==)
{
cin>>y>>z;
cout<<query1(,y,z)<<endl;
}
if (x==)
{
cin>>y>>z;
cout<<query2(,y,z)<<endl;
}
}
}
return ;
}
[HDU] 5306 Gorgeous Sequence [区间取min&求和&求max]的更多相关文章
- HDU 5306 Gorgeous Sequence[线段树区间最值操作]
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence
Gorgeous Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- HDU - 5306 Gorgeous Sequence (吉司机线段树)
题目链接 吉司机线段树裸题... #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3 ...
- HDU 5306 Gorgeous Sequence
如果维护max,sum,那么可以得到一个暴力方法,如果t>=max,那可以return,否则往下更新,显然超时. 在上面基础上,再维护一下次大值,与最大值的个数.这样一来,次大值<t< ...
- HDU - 5306 Gorgeous Sequence 线段树 + 均摊分析
Code: #include<algorithm> #include<cstdio> #include<cstring> #define ll long long ...
- HDOJ 5306 Gorgeous Sequence 线段树
http://www.shuizilong.com/house/archives/hdu-5306-gorgeous-sequence/ Gorgeous Sequence Time Limit: 6 ...
- [NOI2005]维修数列 Splay tree 区间反转,修改,求和,求最值
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1500 Description Input 输入文件的第1行包含两个数N和M,N表示初始时数 ...
- bzoj 4695: 最假女选手 && Gorgeous Sequence HDU - 5306 && (bzoj5312 冒险 || 小B的序列) && bzoj4355: Play with sequence
算导: 核算法 给每种操作一个摊还代价(是手工定义的),给数据结构中某些东西一个“信用”值(不是手动定义的,是被动产生的),摊还代价等于实际代价+信用变化量. 当实际代价小于摊还代价时,增加等于差额的 ...
- 【hdu5306】 Gorgeous Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5306 (题目链接) 题意 区间取$min$操作,区间求和操作,区间求最值操作. Solution 乱搞一通竟然A ...
随机推荐
- castle动态代理的使用
转自:https://blog.csdn.net/educast/article/details/6565447#动态代理的原理 原理其实很简单,就是在运行时生成新的对象,姑且叫做T,并使T继承自需要 ...
- MVC 部分视图:Partial() 、RenderPartial() 、 Action() 、RenderAction() 、 RenderPage() 区别
在视图里有多种方法可以 加载部分视图,包括: Partial() Action() RenderPartial() RenderAction() RenderPage() 方法. 以下是这些方 ...
- 阿里云服务器安装SQLServer本地无法远程访问
新买的阿里云服务器,安装上sqlserver2012,本机连接测试没有问题,但是回到本地,使用ip远程连接报错. 尝试了网上各种办法,都是失败.最后找到原因,原来在阿里云的控制台上有设置: 首先进入安 ...
- C# 摇奖机实例(线程)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Postfix 邮件服务 - DNS服务
DNS 服务 (系统需要配置静态 IP 地址) yum install bing* -y 一.配置 NDS 域名解析: 直接添加以下内容: [root@mail ~]# cat /etc/named. ...
- Ansi与Unicode编码
视频教程:Ansi与Unicode编码 大家在编程时经常遇到的数据类型: ● Ansi: char 代表一个字符 (CHAR) char * 代表一个字符串指针 (PCHAR PST ...
- position属性absolute与relative 的区别
连接:https://www.cnblogs.com/duyanli/p/3534005.html 每次要用到Position属性时,总要去搜索下,这两个属性值的区别:今天就直接复制网上的结果,以便以 ...
- luogu P4036 [JSOI2008]火星人
传送门 很久以前xzz大佬就喊我做这题,结果现在才做qwq 因为要在序列中插入,所以直接用\(Splay\)维护这个串的哈希值,插入就直接把那个点插♂进去,修改就把点旋到根,然后修改和pushup,询 ...
- mysql原理~undo
mysql undo详谈1 简介:undo是MVCC机制的基础部分之一2 作用:为了实现可重复性读,存储历史数据3 存储:5.6以前undo都存储在内存和ibdata1中,5.6以后undo可以独立成 ...
- Linux串口—struct termios结构体【转】
转自:https://blog.csdn.net/yemingzhu163/article/details/5897156 一.数据成员 termios 函数族提供了一个常规的终端接口,用于控制非同步 ...