/*	query kth-maximum	*/
	inline void query(int x, const point &p, int k, pair<long long, int> ret[], bool dim = 0) {
		if (tree[x].r.dist(p) < ret[k].first) {
			return;
		}
		pair<long long, int> val = make_pair(dist(tree[x].p, p), -tree[x].p.id);
		for (int i = 1; i <= k; ++i) {
			if (val > ret[i]) {
				for (int j = k + 1; j > i; --j) {
					ret[j] = ret[j - 1];
				}
				ret[i] = val;
				break;
			}
		}
		if (dim && xcompare(p, tree[x].p) || !dim && ycompare(p, tree[x].p)) {
			if (tree[x].child[1]) {
				query(tree[x].child[1], p, k, ret, dim ^ 1);
			}
			if (tree[x].child[0]) {
				query(tree[x].child[0], p, k, ret, dim ^ 1);
			}
		} else {
			if (tree[x].child[0]) {
				query(tree[x].child[0], p, k, ret, dim ^ 1);
			}
			if (tree[x].child[1]) {
				query(tree[x].child[1], p, k, ret, dim ^ 1);
			}
		}
	}
Beispiel #2
0
// Derived verb for f//. y
static DF1(jtobqfslash){A y,z;B b=0,p;C er,id,*wv;I c,d,k,m,m1,mn,n,n1,r,*s,wt;
 RZ(w);
 r=AR(w); s=AS(w); wt=AT(w); wv=CAV(w);
 if(!(AN(w)&&1<r&&DENSE&wt))R oblique(w,self);  // revert to default if rank<2, empty, or sparse
 y=VAV(self)->f; y=VAV(y)->f; id=vaid(y);
 m=s[0]; m1=m-1;
 n=s[1]; n1=n-1; mn=m*n; d=m+n-1; PROD(c,r-2,2+s);
 if(1==m||1==n){GA(z,wt,AN(w),r-1,1+s); *AS(z)=d; MC(AV(z),wv,AN(w)*bp(wt)); R z;}
 if(wt&FL+CMPX)NAN0;
 if(1==c)switch(OBQCASE(CTTZ(wt),id)){
  case OBQCASE(B01X, CNE     ): OBQLOOP(B,B,wt,x=*u, x^=*u        ); break;
  case OBQCASE(B01X, CEQ     ): OBQLOOP(B,B,wt,x=*u, x=x==*u      ); break;
  case OBQCASE(B01X, CMAX    ):
  case OBQCASE(B01X, CPLUSDOT): OBQLOOP(B,B,wt,x=*u, x|=*u        ); break;
  case OBQCASE(B01X, CMIN    ):
  case OBQCASE(B01X, CSTAR   ):
  case OBQCASE(B01X, CSTARDOT): OBQLOOP(B,B,wt,x=*u, x&=*u        ); break;
  case OBQCASE(B01X, CLT     ): OBQLOOP(B,B,wt,x=*u, x=*u< x      ); break;
  case OBQCASE(B01X, CLE     ): OBQLOOP(B,B,wt,x=*u, x=*u<=x      ); break;
  case OBQCASE(B01X, CGT     ): OBQLOOP(B,B,wt,x=*u, x=*u> x      ); break;
  case OBQCASE(B01X, CGE     ): OBQLOOP(B,B,wt,x=*u, x=*u>=x      ); break;
  case OBQCASE(B01X, CPLUS   ): OBQLOOP(B,I,INT,x=*u, x+=*u       ); break;
  case OBQCASE(SBTX, CMAX    ): OBQLOOP(SB,SB,wt,x=*u, x=SBGT(x,*u)?x:*u ); break;
  case OBQCASE(SBTX, CMIN    ): OBQLOOP(SB,SB,wt,x=*u, x=SBLT(x,*u)?x:*u ); break;
  case OBQCASE(FLX,  CMAX    ): OBQLOOP(D,D,wt,x=*u, x=MAX(x,*u)  ); break;
  case OBQCASE(FLX,  CMIN    ): OBQLOOP(D,D,wt,x=*u, x=MIN(x,*u)  ); break;
  case OBQCASE(FLX,  CPLUS   ): OBQLOOP(D,D,wt,x=*u, x+=*u        ); break;
  case OBQCASE(CMPXX,CPLUS   ): OBQLOOP(Z,Z,wt,x=*u, x=zplus(x,*u)); break;
  case OBQCASE(XNUMX,CMAX    ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)? x:*u); break;
  case OBQCASE(XNUMX,CMIN    ): OBQLOOP(X,X,wt,x=*u, x=1==xcompare(x,*u)?*u: x); break;
  case OBQCASE(XNUMX,CPLUS   ): OBQLOOP(X,X,wt,x=*u, x=xplus(x,*u)); break;
  case OBQCASE(RATX, CMAX    ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)? x:*u); break;
  case OBQCASE(RATX, CMIN    ): OBQLOOP(Q,Q,wt,x=*u, x=1==QCOMP(x,*u)?*u: x); break;
  case OBQCASE(RATX, CPLUS   ): OBQLOOP(Q,Q,wt,x=*u, x=qplus(x,*u)); break;
  case OBQCASE(INTX, CBW0001 ): OBQLOOP(I,I,wt,x=*u, x&=*u        ); break;
  case OBQCASE(INTX, CBW0110 ): OBQLOOP(I,I,wt,x=*u, x^=*u        ); break;
  case OBQCASE(INTX, CBW0111 ): OBQLOOP(I,I,wt,x=*u, x|=*u        ); break;
  case OBQCASE(INTX, CMAX    ): OBQLOOP(I,I,wt,x=*u, x=MAX(x,*u)  ); break;
  case OBQCASE(INTX, CMIN    ): OBQLOOP(I,I,wt,x=*u, x=MIN(x,*u)  ); break;
  case OBQCASE(INTX, CPLUS   ): 
   er=0; OBQLOOP(I,I,wt,x=*u, {p=0>x; x+=*u; BOV(p==0>*u&&p!=0>x);}); 
   if(er>=EWOV)OBQLOOP(I,D,FL,x=(D)*u, x+=*u);
 }
	inline int insert(int x, const point &p, bool dim = 0) {
		if (x == 0) {
			tree[++size].set(p);
			return size;
		}
		tree[x].r.mergy(p);
		if (dim && xcompare(p, tree[x].p) || !dim && ycompare(p, tree[x].p)) {
			tree[x].child[0] = insert(tree[x].child[0], p, dim ^ 1);
		} else {
			tree[x].child[1] = insert(tree[x].child[1], p, dim ^ 1);
		}
		return x;
	}
	/*	query maximum	*/
	inline void query(int x, const point &p, long long &ret, bool dim = 0) {
		if (tree[x].r.dist(p) <= ret) {
			return;
		}
		ret = max(ret, dist(tree[x].p, p));
		if (dim && xcompare(p, tree[x].p) || !dim && ycompare(p, tree[x].p)) {
			if (tree[x].child[1]) {
				query(tree[x].child[1], p, ret, dim ^ 1);
			}
			if (tree[x].child[0]) {
				query(tree[x].child[0], p, ret, dim ^ 1);
			}
		} else {
			if (tree[x].child[0]) {
				query(tree[x].child[0], p, ret, dim ^ 1);
			}
			if (tree[x].child[1]) {
				query(tree[x].child[1], p, ret, dim ^ 1);
			}
		}
	}