Descriptionsay one day Doyouloveme and vfleaking to play in the mountains. Behold Doyouloveme just into the mountain, all the birds unexpectedly by his God Ben gas field to all fly away. Vfleaking immediately worship unceasingly. then the bird King said with the birds: "[email protected]#$% ...?"] Soothed the mood of the birds. The bird King was aggressive and made a decision to arrange the birds to get out of the human race that had just frightened them. each bird has a number that has a mighty value. Every second the bird King sends an order, the bird with the number V flies to (x, y) to go (the coordinate system origin is the peak, the coordinate unit is the bird claw). The bird flies quickly, flies within a second, and can be seen as an instantaneous movement. If a bird numbered V and a bird numbered u are in the same position at some point, they will encourage each other to increase their morale and unity values. The morale of a bird is equal to the maximum value of the mighty value of the bird in the same position at the moment, and the unity value equals the number of birds at the same position at the moment. If no bird is in the same position at every moment, the morale value and the unity value are all 0. Be aware that you cannot encourage yourself to count morale and unity values. t seconds later, Doyouloveme visual out of each bird's combat effectiveness, so exclaimed: "Bad, we have to go." "the so-called United Birds are a top two, so Doyouloveme describes combat effectiveness: a bird's combat effectiveness is equal to its maximum value of morale in 0 to t seconds multiplied by the maximum value of the unity value. Note that it is not the maximum value of the product, but the product of the maximum value. Vfleaking wanted to know the effectiveness of every bird now, but of course he didn't, so he gave it to you to finish it. InputThe first row is a number n, which represents the number of birds. (Bird King that guy you can totally ignore)Next n lines, three integers per line w,x,y describe the mighty and initial coordinates of each bird. Line i+1 describes the bird numbered I. the next line has a number T, which represents the elapsed time TS. Next T line, three integers per line v,x,y describe the bird King command per second. Outputa total of n rows, a number per line, representing the combat effectiveness of each bird.
Build a node for each bird, maintain a balanced tree for each coordinate, maintain the mark (interval maximum/secondary value, size, full tree maximum/secondary value, size, single point history max/Sub Large value, history maximum size, etc.), each operation corresponds to the insertion and deletion of the balance tree, After all the questions have been dealt with, the final violence passes all the marks.
#include <cstdio>#include<cstdlib>int _(){ intx=0, C=getchar (), f=1; while(c< -) c=='-'&& (f=-1), c=GetChar (); while(c> -) x=x*Ten+c- -, c=GetChar (); returnx*F;}Const intp=621239;inth[p][4];int&Get(intXinty) { intW=unsigned (x*1844677+y*293+141)%P; while(h[w][2]){ if(h[w][0]==x&&h[w][1]==y)returnh[w][3]; if((w+=12347) >=p) w-=P; } h[w][0]=x;h[w][1]=y;h[w][2]=1; returnh[w][3];} InlinevoidMAXS (int&a,intb) {if(a<b) a=b;}intn,q;structnode{intrnd,v0,x,y,ch[2],m1,m2,m3,mt[3], as[3]; voidIns (); voidDel (); Long LongVal () {return1ll* (v0== as[0]? as[1]: as[0])*( as[2]-1); } voidCLR () {ch[0]=ch[1]=0; M1=v0;m2=0; m3=1; for(intI=0;i<3; ++i) mt[i]=0; } voidupd () {mt[0]=m1;mt[1]=m2;mt[2]=m3; for(intI=0;i<3; ++i) Maxs ( as[I],mt[i]); }}ns[30007];inlinevoidChkint&a,int&b,intc) { if(c>=a) b=a,a=C; Else if(c>b) b=C;} InlinevoidMAXS (int&a,int&b,intc) { if(a<c) a=C; if(b<c) b=C;}voidDnintW) { for(intD=0,u;d<2; ++d)if(u=Ns[w].ch[d]) { for(intj=0;j<3; ++j) Maxs (Ns[u].mt[j],ns[u]. as[j],ns[w].mt[j]); } for(intj=0;j<3; ++j) ns[w].mt[j]=0;}voidDNsintW) { if(!W)return; DN (w); for(intD=0;d <2;++d) DNS (Ns[w].ch[d]);}voidUpintW) {NS[W].M1=ns[w].v0;ns[w].m2=0; ns[w].m3=1; for(intD=0,u;d<2; ++d)if(u=Ns[w].ch[d]) {chk (NS[W].M1,NS[W].M2,NS[U].M1); CHK (NS[W].M1,NS[W].M2,NS[U].M2); NS[W].M3+=ns[u].m3; }}voidRotint&w,intd) { intu=Ns[w].ch[d]; DN (W);d N (u); NS[W].CH[D]=ns[u].ch[d^1]; Ns[u].ch[d^1]=W; Up (W), Up (U); W=u;}voidInsint&w,intx) { if(!W) {W=x; return; } DN (w); intd=w<x; Ins (ns[w].ch[d],x); if(ns[ns[w].ch[d]].rnd>ns[w].rnd) Rot (w,d); ElseUp (w);}voidDelsint&W) { if(ns[w].ch[0]|ns[w].ch[1]){ intd=ns[ns[w].ch[0]].rnd<ns[ns[w].ch[1]].rnd; Rot (w,d); Dels (Ns[w].ch[d^1]); Up (W); }Elsew=0;}voidDelint&w,intx) { if(w==x) {dels (w); return; } DN (w); intd=w<x; Del (NS[W].CH[D],X); if(ns[ns[w].ch[d]].rnd>ns[w].rnd) Rot (w,d); ElseUp (w);}voidNode::ins () {CLR (); int&rt=Get(x, y); INS (RT, This-, s); NS[RT].UPD ();}voidnode::D El () {int&rt=Get(x, y); Del (RT, This-NS); if(RT) ns[rt].upd (); CLR ();}intMain () {Srand (29397); N=_(); for(intI=1; i<=n;++i) {Ns[i].v0=_(); ns[i].x=_(); Ns[i].y=_(); Ns[i].rnd=rand (); Ns[i]. Ins (); } for(Q=_ (); q;--q) { intI=_(); Ns[i]. Del (); ns[i].x=_(); Ns[i].y=_(); Ns[i]. Ins (); } for(intI=0; i<p;++i) DNS (h[i][3]); for(intI=1; i<=n;++i) printf ("%lld\n", Ns[i].val ()); return 0;}
bzoj2827: Qianshan birds Fly