题意:见题面 思路:因为每个时刻要么全是人要么全是宠物,所以可以一棵splay解决 维护单点插入,单点删除,求前驱,求后继即可 ..,..]of longint; num,fa:..]of longint; n,cnt,t1,t2,i,root,p,x,y:longint; ans:int64; procedure rotate(x:longint;var k:longint); var y,z,l,r:longint; begin y:=fa[x]; z:=fa[y]; ]=x ; r:=-l…