Description
Maintains a collection of vectors that support the following operations online:
"A x Y (|x|,|y| < =10^8) ": Add vector (x, y);
"Q x y L R (|x|,|y| < =10^8,1 < =l < =r < =t, where T is the number of vectors that have been added, ask for the maximum value of the dot product of the vector and vector (x, y) added to the R of the first.
The collection was initially empty.
Input
The first line of input contains the integer n and the character s, respectively, representing the operands and data categories;
Next n rows, one action per line, formatted as described above.
Note that all integers in the input are encrypted when s≠ ' E '. You can use the following program
Get the original input:
inline int decode (int x long long Lastans) {
return x ^ (Lastans & Ox7fffffff);
}
function decode
Begin
where x is the number that the program reads, Lastans is the answer to the last query. Before the first inquiry, lastans=0.
Note: The dot product of vector (x, y) and (Z,W) is defined as XZ+YW.
Output
For each q operation, output an integer to indicate the answer.
The vector is considered as a point on the plane, the segment tree maintains the upper and lower convex packets, and the optimal solution is obtained by three points on the convex hull. For each interval of the segment tree, the convex hull is computed when the intra-interval vector is read.
#include <cstdio>#include<algorithm>typedefLong Longi64;Charbuf[5000000],*ptr=buf,*pmx=buf+5000000;ConstI64 inf=1ll<< +;Const intn=1e7;intg () {if(PTR==PMX) fread (Ptr=buf,1,5000000, stdin); return*ptr++;}int _(){ intx=0, f=1, c=g (); while(c< -|| C> $) c=='-'&& (f=-1), c=g (); while(c> -&&c< -) x=x*Ten+c- -, c=g (); returnx*F;}int_c () {intC=g (); while(c<'A'|| C>'Z') c=g (); returnC;}voidMaxs (i64&a,i64 b) {if(a<b) a=b;}voidMAXS (int&a,intb) {if(a<b) a=b;}voidminsint&a,intb) {if(a>b) a=b;}structpos{intx, y; I64operator() (pos a) {returni64 (x) *a.x+i64 (y) *a.y; }}mem[21000007],*mp=Mem;posoperator-(pos A,pos b) {return(POS) {a.x-b.x,a.y-b.y};} I64operator*(pos A,pos b) {returnI64 (a.x) *b.y-i64 (A.Y) *b.x;}BOOL operator<(pos A,pos b) {returna.x!=b.x?a.x<b.x:a.y<b.y;}structnode{POS*l,*R; voidInitintXinty) {L=MP; *mp++=(POS) {x, y}; R=MP; } voidins (pos x) {if(mp>l&&mp[-1].x==x.x)--MP; while(mp-l>=2&& (x-mp[-1]) * (mp[-2]-mp[-1]) >=0)--MP; *mp++=x; } voidInit (node A,node b) {if(!A.L) * This=b; Else if(!B.L) * This=A; Else{L=MP; POS*ap=a.l,*bp=B.L; while(ap!=a.r&&bp!=B.R) { if(*AP<*BP) Ins (*ap++); ElseINS (*bp++); } while(AP!=A.R) Ins (*ap++); while(BP!=B.R) Ins (*bp++); R=MP; }} i64 find (pos x) {if(!l)return-1ll<< +; I64 V1,v2; intL=0, r=r-l-1, m1,m2; while(r-l>3) {M1=l+r>>1; M2=m1+1; if(x (L[M1]) <x (l[m2])) L=M1; ElseR=M2; } for(V1=x (l[l++]); l<=r;++L) Maxs (v1,x (l[l)); returnv1; }}us[1051111],ds[1051111];BOOLd[1051111];intN,de,la=0, x,y,l,r,id=0;intMain () {n=_ ();d e=_c ()! ='E'; for(intI=0; i<n;++i) { if(_c () = ='A') {x=_ (); y=_ (); + +ID; if(DE) x^=la,y^=LA; intW=id+524288; Us[w].init (x, y); Ds[w].init (x,-y); D[W]=1; for(w>>=1;w&&d[w<<1^1];w>>=1) {us[w].init (us[w<<1],us[w<<1^1]); Ds[w].init (Ds[w<<1],ds[w<<1^1]); D[W]=1;d [w<<1^1]=0; } }Else{x=_ (); Y=_ (); L=_ (); r=_(); if(DE) x^=la,y^=la,l^=la,r^=LA; i64 ans=-1ll<< +; POS P1= (POS) {x,y},p2= (pos) {x,-y}; for(l+=524287, r+=524289; l^r^1; l>>=1, r>>=1){ if(~l&1) Maxs (ans,us[l^1].find (p1)), Maxs (ans,ds[l^1].find (p2)); if(r&1) Maxs (ans,us[r^1].find (p1)), Maxs (ans,ds[r^1].find (p2)); } printf ("%lld\n", ans); La=ans&0x7fffffff; } } return 0;}
bzoj3533: [Sdoi2014] Vector set