Discrete coordinates, each of which opens a balanced tree with the number of birds as the key. Make 2 marks each time you insert, and update yourself. This method is more obvious and good to write. The positive solution seems to be a very confusing way to make a wave, and then use a line of tree do not hit the mark on it, and will not.
Treap rotation did not pass the reference, adjusted for a long time.
#include <bits/stdc++.h> #define N 30005#define M 330005#define x first#define y second#define IF else ifusing Namespa CE std;int n,m,i,v[m];typedef int ds[n];d s f,l,r,z;typedef pair<int,int> vec;vec a[m],s[m];struct node{int v,a,i,j , S,q;node *r,*l;} *t[m],e[m];node* back=e+1;node* null=e;node* Create (int v) {return & (*back++= (node) {V,z[v],0,0,1,rand (), e,e});} void update (Node* t) {T->s=t->l->s+t->r->s+1;t->a=max (max (t->l->a,t->r->a),z[t-> V]);} void Lturn (node*& t) {node* s=t->r;t->r=s->l;update (s->l=t); update (t=s);} void Rturn (node*& t) {node* s=t->l;t->l=s->r;update (s->r=t); update (t=s);} void Eq2 (int& a,int b) {a=a<b?b:a;} void devolve (node* s) {EQ2 (s->l->i,s->i); eq2 (s->l->j,s->j); eq2 (s->r->i,s->i); EQ2 (S- >R->J,S->J); eq2 (l[s->v],s->i); eq2 (r[s->v],s->j); s->i=s->j=0;} void Insert (int v,node*& s) {if (s==null) s=create (v);d evolve (s), if (v<s->v) {Insert (V,S->L); if (s->l->q>s->q) Rturn (s);} if (s->v<v) {insert (V,S->R); if (s->r->q>s->q) Lturn (s);} Update (s);} void Erase (int v,node*& s) {devolve (s), if (v<s->v) erase (V,s->l), if (s->v<v) erase (V,s->r), if (s >l==null) {S=s->r;return;} IF (s->r==null) {S=s->l;return;} IF (s->l->q>s->r->q) {devolve (s->l); Rturn (s); erase (v,s->r);} Else{devolve (S->r); Lturn (s); erase (v,s->l);} Update (s);} void Come (int v,node*& s) {EQ2 (s->i,z[v]); EQ2 (s->j,s->s); eq2 (l[v],s->a); eq2 (r[v],s->s); Insert (v , s);} void Dfs (node* t) {if (t!=null) {devolve (T);d FS (t->l);d FS (T->r);}} int main () {srand (20000327); scanf ("%d", &n), for (I=1;i<=n;++i) {scanf ("%d%d%d", z+i,&a[i].x,&a[i].y); S[i]=a[i];} scanf ("%d", &m), for (I=n+1;i<=n+m;++i) {scanf ("%d%d%d", v+i,&a[i].x,&a[i].y); s[i]=a[i];} Sort (s+1,s+n+m+1), for (I=1;i<=n+m;++i) t[i]=null;for (i=1;i<=n;++i) Come (I,t[f[i]=lower_bound (s+1,s+n+m+1,a[ I])-S]); for (i=n+1;i<=n+m;++i) {eraSE (V[i],t[f[v[i]]); Come (V[i],t[f[v[i]]=lower_bound (S+1,s+n+m+1,a[i])-S]);} for (i=1;i<=n;++i) {DFS (t[f[i]), t[f[i]]=null;printf ("%lld" "\ n", 1ll*l[i]*r[i]);}}
bzoj2827: Qianshan birds Fly Treap