[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 ...
随机推荐
- 视频聊天 Demo
ESFramework Demo -- 入门Demo,简单的即时通讯系统(附源码) 是基于ESFramework实现的一个简单的文字聊天demo,现在,我们将在这个demo的基础上,使用OMCS为其增 ...
- 第九条:覆盖equals方法时总要覆盖hashCode方法
Object类的hashCode方法: public native int hashCode(); 是一个本地方法. 其中这个方法的主要注释如下: Whenever it is invoked o ...
- JAVA_SE基础——10.变量的作用域
<pre name="code" class="java"> 上个月实在太忙了,从现在开始又可以静下心来写blog了. 变量的作用域指 可以使用此变 ...
- 使用 slf4j抽象日志层 和 其他日志实现对接
前言 如果你正在提供一个开源的Java-jar,那么让你的项目仅依赖slf4j-api然后让你的用户在他们开发和运营环境中选择任意的日志实现绝对是个好想法,.作为终端用户,他们可以快速地从上面提到的日 ...
- Mysql中autocommit的用法
定义 Mysql文档原文:SET autocommit disables or enables the default autocommit mode for the current session. ...
- redis从入门到
下载 首先我们要到GitHub(https://github.com/MicrosoftArchive/redis/releases)上下载Source code (tar.gz) 上传到Linux上 ...
- flask开发表单
from flask import Flask from flask import render_template from flask import request from flask impor ...
- Selenium+Chrome/phantomJS模拟浏览器爬取淘宝商品信息
#使用selenium+Carome/phantomJS模拟浏览器爬取淘宝商品信息 # 思路: # 第一步:利用selenium驱动浏览器,搜索商品信息,得到商品列表 # 第二步:分析商品页数,驱动浏 ...
- Spring源码情操陶冶-任务定时器ConcurrentTaskScheduler
承接前文Spring源码情操陶冶#task:scheduled-tasks解析器,本文在前文的基础上讲解单核心线程线程池的工作原理 应用附例 承接前文的例子,如下 <!--define bean ...
- sublime高亮代码导出
何在word/博客中使用SublimeText风格的代码高亮样式 原文链接:http://www.cnblogs.com/Wayou/p/highlight_code_with_sublimetext ...