[bzoj4906][BeiJing2017]喷式水战改
来自FallDream的博客,未经允许,请勿转载,谢谢。
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define MN 500005
#define getchar() (*S++)
char BB[<<],*S=BB;
using namespace std;
inline int read()
{
int x = ; char ch = getchar();
while(ch < '' || ch > '') ch = getchar();
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x;
}
inline ll llread()
{
ll x = ; char ch = getchar();
while(ch < '' || ch > '')ch = getchar();
while(ch >= '' && ch <= ''){x = x * + ch - '';ch = getchar();}
return x;
}
struct data
{
ll x[][];
data(){}
data(ll a,ll b,ll c)
{
memset(x,,sizeof(x));
x[][]=x[][]=a;x[][]=b;
x[][]=c;x[][]=max(a,b);
x[][]=max(b,c);x[][]=max(a,c);
x[][]=x[][]=x[][]=max(a,max(b,c));
}
friend data operator + (data a,data b)
{
data c;memset(c.x,,sizeof(c.x));
for(int l=;l<=;++l)
for(int i=;i+l-<;++i)
{
int j=i+l-;c.x[i][j]=;
for(int k=i;k<=j;++k)
c.x[i][j]=max(c.x[i][j],a.x[i][k]+b.x[k][j]);
}
return c;
}
}s[MN+];
int fa[MN+],sz[MN+],c[MN+][],rt=,mark,A[MN+],L[MN+],B[MN+],C[MN+],n,cnt=,q[MN+],top=;
ll size[MN+],tot;
int tms=;
inline void update(int x)
{
s[x]=(data){1LL*A[x]*L[x],1LL*B[x]*L[x],1LL*C[x]*L[x]};
if(c[x][]) s[x]=s[c[x][]]+s[x];
if(c[x][]) s[x]=s[x]+s[c[x][]];
size[x]=size[c[x][]]+size[c[x][]]+L[x];
sz[x]=sz[c[x][]]+sz[c[x][]]+;
} int Find(int x,ll pos)
{
ll Sz1=size[c[x][]],Sz2=Sz1+L[x];
if((Sz1<pos||(!c[x][]&&!pos))&&Sz2>=pos) return x;
if(Sz1>=pos) return Find(c[x][],pos);
return tot+=Sz2,Find(c[x][],pos-Sz2);
} void ins(int&x,int ai,int bi,int ci,ll pos,int len,int last=)
{
if(!x)
{
x=++cnt;s[x]=data(1LL*ai*len,1LL*bi*len,1LL*ci*len);
L[x]=size[x]=len;A[x]=ai;B[x]=bi;C[x]=ci;sz[x]=;fa[x]=last;
return;
}
ll Sz=size[c[x][]]+L[x];
if(Sz<=pos) ins(c[x][],ai,bi,ci,pos-Sz,len,x);
else ins(c[x][],ai,bi,ci,pos,len,x);
update(x);
if(max(sz[c[x][]],sz[c[x][]])>0.7*sz[x]) mark=x;
} void Modify(int x,int k,ll pos,int Len)
{
if(x==k)
{
L[x]=Len;update(x);
return;
}
if(size[c[x][]]>=pos) Modify(c[x][],k,pos,Len);
else Modify(c[x][],k,pos-L[x]-size[c[x][]],Len);
update(x);
} void Dfs(int x)
{
if(c[x][]) Dfs(c[x][]);
q[++top]=x;
if(c[x][]) Dfs(c[x][]);
} void Build(int&x,int l,int r,int last)
{
if(l>r) {x=;return;}
int mid=l+r>>;x=q[mid];fa[x]=last;
Build(c[x][],l,mid-,x);
Build(c[x][],mid+,r,x);
update(x);
} void rebuild(int x)
{
mark=top=;Dfs(x);int y=fa[x];
if(!y) Build(rt,,top,);
else Build(c[y][c[y][]==x],,top,y);
} int main()
{
fread(BB,,<<,stdin);
n=read();ins(rt,,,,,);ll pre=;
for(int i=;i<=n;++i)
{
ll p=llread();
int ai=read(),bi=read(),ci=read(),x=read();
tot=tms=;int k=Find(rt,p);
if(tot+size[c[k][]]+L[k]!=p)
{
ll Left=tot+size[c[k][]]+L[k]-p;
tms=;Modify(rt,k,p,L[k]-Left);
ins(rt,ai,bi,ci,p,x);if(mark) rebuild(mark);
ins(rt,A[k],B[k],C[k],p+x,Left);
}
else ins(rt,ai,bi,ci,p,x);
printf("%lld\n",s[rt].x[][]-pre);
pre=s[rt].x[][];if(mark) rebuild(mark);
}
return ;
}
[bzoj4906][BeiJing2017]喷式水战改的更多相关文章
- BJOI2017 喷式水战改
题目链接. Description 维护一个序列,支持操作: 每次在 \(P_i\) 位置后插入一段 \(X_i\) 单位的燃料,这一段有三个模式,对应的能量分别是 \(A_i, B_i, C_i\) ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- Linux.NET实战手记—自己动手改泥鳅(上)
各位读者大家好,不知各位读者有否阅读在下的前一个系列<Linux.NET 学习手记>,在前一个系列中,我们从Linux中Mono的编译安装开始,到Jexus服务器的介绍,以及如何在Linu ...
- Linux.NET实战手记—自己动手改泥鳅(下)
在上回合中,我们不痛不痒的把小泥鳅的数据库从只能供在Windows下运行的Access数据库改为支持跨平台的MYSQL数据库,毫无营养的修改,本回合中,我们将把我们修改后得来的项目往Linux中部署. ...
- Android 打开方式选定后默认了改不回来?解决方法(三星s7为例)
Android 打开方式选定后默认了改不回来?解决方法(三星s7为例) 刚刚在测试东西,打开一个gif图,然后我故意选择用支付宝打开,然后...支付宝当然不支持,我觉得第二次打开它应该还会问我,没想到 ...
- 把PDF的底色改成护眼色,这样读起文章来就不是很累了······
PDF格式背景改变方法如下: 打开PDF 点击 编辑 ->首选项->辅助工具->选中"替换文档颜色"和" 自定义颜色"->将背景颜色改成 ...
- 3.EF 6.0 Code-First实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...
- 4.在MVC中使用仓储模式进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/ 系列目录: ...
- 5.在MVC中使用泛型仓储模式和工作单元来进行增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
随机推荐
- 第一周-JAVA基本概念
1. 本周学习总结 本周学习内容: 1.JAVA的发展 2.JDK,JVM,JRE, 3.掌握JAVA的组成结构 4.掌握使用简单的编译器写javac与java命令, 关键概念之间的联系: JVM:将 ...
- Packet for query is too large (84 > -1).
windows下的resin配置连接mysql,常用的安全的做法是将数据库信息配置到conf目录下的resin.xml文件中. 因为resin连接mysql不是必须的,所以resin本身没有提供mys ...
- Python内置函数(43)——type
英文文档: class type(object) class type(name, bases, dict) With one argument, return the type of an obje ...
- SpringCloud的Config:ConfigServer注册到EurekaServer中,变成一个Eureka服务
一.概念与定义 1.将SpringCloud ConfigServer注册到 EurekaServer,以便ConfigClient以服务的方式引用ConfigServer 2.客户端不再引用 Con ...
- ASP.NET CORE系列【三】使用Entity Framework Core进行增删改查
身份验证 以前我们熟悉的web.config中配置的form验证,现在没有了.我们来看看在Core里面如何配置: 首先需要NuGet安装一个包:Microsoft.AspNetCore.Authent ...
- python实现归并排序,归并排序的详细分析。
学习归并排序的过程是十分痛苦的.它并不常用,看起来时间复杂度好像是几种排序中最低的,比快排的时间复杂度还要低,但是它的执行速度不是最快的.很多朋友不理解时间复杂度低为什么运行速度不一定快,这个不清楚的 ...
- Oracle:如何使用PL/SQL 11.0连接远程Oracle12c服务器?
背景: 如何实现远程连接服务器上的oracle12c? 1.安装一个oracle12c空库,使用oracle12c中集成的oracle pl/sql developer工具实现连接远程服务器上的ora ...
- linux添加超级用户
创建super账号 useradd testuser 创建用户testuser passwd testuser 给已创建的用户testuser设置密码 如果需要让此用户有root权限,执行命令: ro ...
- 有没有想过css定位与xpath的区别
我是这样理解的, css选择如同你尽可能具体的描述一个元素的形态, 包括他的: 标签, 类, id 以及这些的组合, 目标是尽可能确定元素的唯一坐标 , 以方便选择. 而xpath是根据元素的路径去确 ...
- js分页效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...