题意:
乱七八糟。
题解:
坐标没卵用,直接map掉就好。
然后对每一个位置开一个splay,直接删点,加点。标记一下。
最后输出的时候都splay下就好了。
细节略多需小心。
code:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<map>
#include<algorithm>
#include<utility>
#define LL long long
using namespace std;
map<pair<int,int>,int> mp;int num=0;
int w[30010],t[30010],s[30010];
int root[350000];
struct trnode{
int fa,son[2],w,t,n;
int lw,lt;
}tr[30010];
int a[30010];
int n;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void add(int x,int fa)
{
tr[x].fa=fa;tr[x].w=a[x];tr[x].t=0;tr[x].n=1;
tr[x].son[0]=tr[x].son[1]=0;
tr[fa].son[x<fa?0:1]=x;
}
void update(int x)
{
int lc=tr[x].son[0],rc=tr[x].son[1];
tr[x].n=tr[lc].n+tr[rc].n+1;
tr[x].w=max(a[x],max(tr[lc].w,tr[rc].w));
tr[x].t=tr[x].n-1;
w[x]=max(max(tr[lc].w,tr[rc].w),w[x]);t[x]=max(t[x],tr[x].t);
if(tr[x].lw!=0)
{
w[lc]=max(w[lc],tr[x].lw);
tr[lc].lw=max(tr[lc].lw,tr[x].lw);
w[rc]=max(w[rc],tr[x].lw);
tr[rc].lw=max(tr[rc].lw,tr[x].lw);
tr[x].lw=0;
}
if(tr[x].lt!=0)
{
t[lc]=max(t[lc],tr[x].lt);
tr[lc].lt=max(tr[lc].lt,tr[x].lt);
t[rc]=max(t[rc],tr[x].lt);
tr[rc].lt=max(tr[rc].lt,tr[x].lt);
tr[x].lt=0;
}
}
void pushdown(int x)
{
if(tr[x].fa) pushdown(tr[x].fa);
update(x);
}
void rotate(int x)
{
int y=tr[x].fa,z=tr[y].fa,w,R,r;
w=tr[y].son[0]==x;
R=y;r=tr[x].son[w];
tr[R].son[1-w]=r;
if(r) tr[r].fa=R;
R=z;r=x;
tr[R].son[tr[z].son[1]==y]=r;
if(r) tr[r].fa=R;
R=x;r=y;
tr[R].son[w]=r;
if(r) tr[r].fa=R;
update(y);update(x);
}
void splay(int x,int fa,int r)
{
pushdown(x);
while(tr[x].fa!=fa)
{
int y=tr[x].fa,z=tr[y].fa;
if(z==fa) rotate(x);
else
if((tr[z].son[0]==y)==(tr[y].son[0]==x)) rotate(y),rotate(x);
else rotate(x),rotate(x);
}
if(fa==0) root[r]=x;
}
int findip(int d,int r)
{
int x=root[r];
while(x!=d)
{
update(x);
int lc=tr[x].son[0],rc=tr[x].son[1];
if(x<d)
if(rc==0) break;
else x=rc;
else
if(lc==0) break;
else x=lc;
}
return x;
}
void ins(int x,int r)
{
if(root[r]==0){add(x,0);root[r]=x;return;}
int fa=findip(x,r);
add(x,fa);
update(fa);
splay(x,0,r);
tr[x].lw=a[x];tr[x].lt=tr[x].t;
}
void clear(int x){s[x]=tr[x].t=tr[x].w=tr[x].fa=tr[x].n=tr[x].son[0]=tr[x].son[1]=tr[x].lw=tr[x].lt=0;}
void del(int x,int r)
{
splay(x,0,r);
if(tr[x].son[0]==0&&tr[x].son[1]==0){root[r]=0;clear(x);return;}
if(tr[x].son[0]!=0&&tr[x].son[1]==0){root[r]=tr[x].son[0];tr[root[r]].fa=0;clear(x);return;}
if(tr[x].son[0]==0&&tr[x].son[1]!=0){root[r]=tr[x].son[1];tr[root[r]].fa=0;clear(x);return;}
int p=tr[x].son[0];
while(tr[p].son[1]!=0) p=tr[p].son[1];
splay(p,x,r);
root[r]=p;tr[root[r]].fa=0;
int R=p,rr=tr[x].son[1];
tr[R].son[1]=rr;
if(rr) tr[rr].fa=R;
update(R);clear(x);
}
int qs(int x,int y)
{
if(mp[make_pair(x,y)]==0) mp[make_pair(x,y)]=++num;
return mp[make_pair(x,y)];
}
void print()
{
for(int x=1;x<=n;x++)
{
splay(x,0,s[x]);
printf("%lld\n",(LL)w[x]*(LL)t[x]);
}
}
int main()
{
mp.clear();
n=read();
for(int i=1;i<=n;i++)
{
int x,y;a[i]=read();x=read();y=read();
s[i]=qs(x,y);
ins(i,s[i]);
}
int m;m=read();
while(m--)
{
int i,x,y;i=read();x=read();y=read();
del(i,s[i]);
s[i]=qs(x,y);
ins(i,s[i]);
}
print();
}