# [BZOJ3747] [POI2015]Kinoman

### 传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=3747

### 题解

const
maxn=1000005;
type
nametype=record
l,r:longint; val,tag:int64; end;
var
w:array[0..4*maxn]of nametype;
x,y,z,v,pre,next:array[0..maxn]of longint;
i,j,k:longint;
n,m:longint;
tt,ans:int64;
function max(a,b:int64):int64;
begin
if a>b then exit(a) else exit(b);
end;

procedure build(a,l,r:longint);
var mid:longint;
begin
w[a].l:=l; w[a].r:=r; w[a].val:=0; w[a].tag:=0;
if l=r then exit;
mid:=(l+r)>>1;
build(a<<1,l,mid); build(a<<1+1,mid+1,r);
end;

procedure pushdown(a:longint);
begin
if w[a].l=w[a].r then begin w[a].tag:=0; exit; end;
inc(w[a<<1].val,w[a].tag); inc(w[a<<1+1].val,w[a].tag);
inc(w[a<<1].tag,w[a].tag); inc(w[a<<1+1].tag,w[a].tag);
w[a].tag:=0;
end;

procedure update(a,l,r:longint;c:int64);
var mid:longint;
begin
if l>r then exit;
if w[a].tag<>0 then pushdown(a);
if (l=w[a].l)and(r=w[a].r) then begin inc(w[a].val,c); inc(w[a].tag,c); exit; end;
mid:=(w[a].l+w[a].r)>>1;
if r<=mid then update(a<<1,l,r,c) else
if l>mid then update(a<<1+1,l,r,c)
else begin update(a<<1,l,mid,c); update(a<<1+1,mid+1,r,c); end;
w[a].val:=max(w[a<<1].val,w[a<<1+1].val);
end;

function query(a,l,r:longint):int64;
var mid:longint;
begin
if w[a].tag<>0 then pushdown(a);
if (l=w[a].l)and(r=w[a].r) then exit(w[a].val);
mid:=(w[a].l+w[a].r)>>1;
if r<=mid then exit(query(a<<1,l,r)) else
if l>mid then exit(query(a<<1+1,l,r))
else exit(max(query(a<<1,l,mid),query(a<<1+1,mid+1,r)));
end;

begin
for i:=1 to n do
begin
if pre[y[i]]=0 then v[i]:=1 else v[i]:=0;
next[pre[y[i]]]:=i;
pre[y[i]]:=i;
end;
for i:=1 to m do
build(1,1,n);
for i:=1 to n do
if v[i]=1
then
if next[i]=0
then update(1,i,n,x[y[i]])
else update(1,i,next[i]-1,x[y[i]]);
ans:=0;
for i:=1 to n do
begin
ans:=max(ans,query(1,i,n));
if next[i]=0
then update(1,i,n,-x[y[i]])
else update(1,i,next[i]-1,-x[y[i]]);
if next[i]<>0
then
if next[next[i]]=0
then update(1,next[i],n,x[y[i]])
else update(1,next[i],next[next[i]]-1,x[y[i]]);
end;
writeln(ans);
end.

• 本文已收录于以下专栏：

举报原因： 您举报文章：[BZOJ3747] [POI2015]Kinoman 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)