CH Round #51 - Shinrein祭 #1

时间:2023-03-08 20:45:13

A.Phorni

题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Phorni

没做。。。

B.Arietta

题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Arietta

想到了网络流,所以每次暴力算出哪些点能被弹奏,就从这次弹奏向哪些点连容量为1的边

最后由s向所有力度连容量为该力度最多能被弹多少次的边,由每个节点连t容量为1的边

求最大流,得到了暴力分30分。正解还不会

代码:

 const inf=maxlongint;maxn=+;maxm=;
type node=record
go,next,v:longint;
end;
var tot,i,n,m,maxflow,l,r,s,t,x,y,tot2:longint;
h,head,head2,q,cur,v:array[..maxn] of longint;
e:array[..maxm] of node;
e2:array[..maxn] of node;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure ins(x,y,z:longint);
begin
inc(tot);
e[tot].go:=y;e[tot].v:=z;e[tot].next:=head[x];head[x]:=tot;
end;
procedure insert(x,y,z:longint);
begin
ins(x,y,z);ins(y,x,);
end;
function bfs:boolean;
var i,x,y:longint;
begin
fillchar(h,sizeof(h),);
l:=;r:=;q[]:=s;h[s]:=;
while l<r do
begin
inc(l);
x:=q[l];
i:=head[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=) then
begin
h[y]:=h[x]+;
inc(r);q[r]:=y;
end;
i:=e[i].next;
end;
end;
exit (h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,y,used,tmp:longint;
begin
if x=t then exit(f);
used:=;
i:=cur[x];
while i<> do
begin
y:=e[i].go;
if (h[y]=h[x]+) and (e[i].v<>) then
begin
tmp:=dfs(y,min(e[i].v,f-used));
dec(e[i].v,tmp);if e[i].v<> then cur[x]:=i;
inc(e[i xor ].v,tmp);
inc(used,tmp);
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end;
procedure dinic;
var i:longint;
begin
while bfs do
begin
for i:=s to t do cur[i]:=head[i];
inc(maxflow,dfs(s,inf));
end;
end;
procedure insert2(x,y:longint);
begin
inc(tot2);
e2[tot2].go:=y;e2[tot2].next:=head2[x];head2[x]:=tot2;
end;
procedure init;
begin
tot:=;
readln(n,m);
for i:= to n do begin read(x);insert2(x,i);end;readln;
for i:= to n do read(v[i]);readln;
end;
procedure dfss(x:longint);
var j,y:longint;
begin
if (v[x]>=l) and (v[x]<=r) then insert(i,x,);
j:=head2[x];
while j<> do
begin
y:=e2[j].go;
dfss(y);
j:=e2[j].next;
end;
end; procedure main;
begin
s:=;t:=n+m+;
for i:= to n do insert(i,t,);
for i:=n+ to n+m do
begin
readln(l,r,x,y);
insert(s,i,y);
dfss(x);
end;
maxflow:=;
dinic;
writeln(maxflow);
end; begin
init;
main;
end.

C。Falsita

题目:http://www.contesthunter.org/contest/CH%20Round%20%2351%20-%20Shinrein祭%20%231/Falsita

我下午刚做了POI的大都市,然后看到这题的对子树的修改就想到了用dfs序+线段树懒惰标记的做法,

最后回答的时候我是O(该点分叉数)求出总数,再用同样时间复杂度的时间求出总代价,使用子树和算的

我想出题人的要求回答询问的该点的分叉树一定很多,就会卡我到超时,结果真是的。。。

于是我又很愉快的拿到了30分。。。正解还不会

代码:

 const maxn=+;
type node=record
go,next:longint;
end;
node2=record
l,r,lch,rch,mid,tag,sum:int64;
end;
var e:array[..*maxn] of node;
t:array[..*maxn] of node2;
head,l,r,s,a,b:array[..*maxn] of longint;
i,n,m,x,y,tot,clock:longint;
ch:char;
procedure insert(x,y:longint);
begin
inc(tot);
e[tot].go:=y;e[tot].next:=head[x];head[x]:=tot;
end;
procedure dfs(x:longint);
var i,y:longint;
begin
inc(clock);l[x]:=clock;a[clock]:=x;
i:=head[x];
while i<> do
begin
y:=e[i].go;
dfs(y);
i:=e[i].next;
end;
inc(clock);r[x]:=clock;a[clock]:=x;
end;
procedure pushup(k:longint);
begin
with t[k] do
begin
sum:=t[lch].sum+t[rch].sum;
end;
end;
procedure build(k,x,y:longint);
begin
with t[k] do
begin
l:=x;r:=y;mid:=(l+r)>>;lch:=k<<;rch:=k<<+;tag:=;
if l=r then begin sum:=b[a[l]];exit;end;
build(lch,l,mid);build(rch,mid+,r);
pushup(k);
end;
end;
procedure update(k:longint;val:int64);
begin
with t[k] do
begin
inc(tag,val);
inc(sum,(r-l+)*val);
end;
end;
procedure pushdown(k:longint);
begin
with t[k] do
begin
if tag= then exit;
update(lch,tag);update(rch,tag);
tag:=;
end;
end;
procedure change(k,x,y:longint);
begin
with t[k] do
begin
if l=r then begin inc(sum,y);exit;end;
pushdown(k);
if x<=mid then change(lch,x,y) else change(rch,x,y);
pushup(k);
end;
end;
procedure change2(k,x,y:longint;z:int64);
begin
with t[k] do
begin
if (l=x) and (r=y) then
begin
update(k,z);exit;
end;
pushdown(k);
if y<=mid then change2(lch,x,y,z)
else if x>mid then change2(rch,x,y,z)
else
begin
change2(lch,x,mid,z);
change2(rch,mid+,y,z);
end;
pushup(k);
end;
end;
function query(k,x,y:longint):int64;
begin
with t[k] do
begin
if (l=x) and (r=y) then exit(sum);
pushdown(k);
if y<=mid then exit(query(lch,x,y))
else if x>mid then exit(query(rch,x,y))
else exit(query(lch,x,mid)+query(rch,mid+,y));
end;
end;
procedure init;
begin
readln(n,m);
for i:= to n do begin read(x);insert(x,i);end;readln;
for i:= to n do read(b[i]);readln;
dfs();
build(,,*n);
for i:= to n do s[i]:=(r[i]-l[i]+)>>;
end;
procedure getans;
var ans:double;
a,b,c:array[..maxn] of int64;
i,x,y,cnt:longint;
tot:int64;
begin
readln(x);a[]:=x;b[]:=s[x];c[]:=trunc(query(,l[x],r[x])/);
cnt:=;
i:=head[x];
while i<> do
begin
y:=e[i].go;
inc(cnt);
a[cnt]:=y;b[cnt]:=s[y];c[cnt]:=trunc(query(,l[y],r[y])/);
dec(c[],c[cnt]);
i:=e[i].next;
end;
tot:=b[]-;
for i:= to cnt do inc(tot,b[i]*(b[]-b[i]));
tot:=tot>>;
ans:=c[]*(b[]-)/tot;
for i:= to cnt do ans:=ans+c[i]*(b[]-b[i])/tot;
writeln(ans::);
end;
procedure main;
begin
for i:= to m do
begin
read(ch);
case ch of
'S':begin
readln(x,y);
change(,l[x],y);change(,r[x],y);
end;
'M':begin
readln(x,y);
change2(,l[x],r[x],y);
end;
'Q':getans;
end;
end;
end;
begin
init;
main;
end.