[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 ...
随机推荐
- Flask 测试
测试是每个应用系统发布前必须经历的步骤,自动化测试对测试效率的提高也是毋庸置疑的.对于Flask应用来说,当然可以使用Web自动化测试工具,比如Selenium等来测.Flask官方推荐的自动化测试方 ...
- Flask学习 一 基本结构
-from flask import Flask +from flask import Flask,render_template -from flask import request -from f ...
- javascript 腾讯ABS云平台面试题及面试经历
既然说到面试前端肯定是Javascript各种问,只好各种答. 面试题肯定离不了,最近热门的Vue.js,React.js,Angular.js,Gulp,Webpack还有各种Js问题,还有令人头痛 ...
- 第四篇:用IntelliJ IDEA 搭建基于jersey的RESTful api
编译器:Intellij IDEA 系统环境: MAC OS 相关技术:Maven.tomcat 7.jdk8 1.创建项目 首先创建一个web Application项目(这里我们打算用maven引 ...
- iis / asp.net 使用 .config 和 .xml 文件的区别
由于在项目中有同学使用后缀为 .xml 的文件作为配置文件,而配置文件中有一些敏感信息被记录,如接口地址,Token,甚至还有数据库连接字符串. 以前都没想过为何微软会使用.config 的后缀在作为 ...
- [Redis源码阅读]redis持久化
作为web开发的一员,相信大家的面试经历里少不了会遇到这个问题:redis是怎么做持久化的? 不急着给出答案,先停下来思考一下,然后再看看下面的介绍.希望看了这边文章后,你能够回答这个问题. 为什么需 ...
- Java面试题合集(二)
接下来几篇文章准备系统整理一下有关Java的面试题,分为基础篇,javaweb篇,框架篇,数据库篇,多线程篇,并发篇,算法篇等等,陆续更新中.其他方面如前端后端等等的面试题也在整理中,都会有的. 注: ...
- python小练习之一
下面的练习本身不难,比如打印1到10,计算1+2+3+...+100 ,最后一个是计算 1-2+3-4...-100 用了类的方法实现 用了列表生成器 用"高级"一丢丢的写法来实现 ...
- 阿里云API网关(15)监控预警
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- 新概念英语(1-19)Tired and thirsty
新概念英语(1-19)Tired and thirsty Why do the children thank their mother? A:What's the matter, children? ...