zoukankan      html  css  js  c++  java
  • 三维数点的CDQ分治板子

    int n, k, tot;
    struct _ {int x,r,f;} a[N];
    struct __ {
    	int type;
    	ll x,y;
    	bool operator < (const __ & rhs) const {
    		if (x!=rhs.x) return x<rhs.x;
    		if (y!=rhs.y) return y<rhs.y;
    		return type<rhs.type;
    	}
    } e[N];
    ll ans, b[N];
    int c[N];
    inline void add(int x, int v) {
    	for (; x<=*b; x+=x&-x) c[x]+=v;
    }
    inline int qry(int x) {
    	int r = 0;
    	for (; x; x^=x&-x) r+=c[x];
    	return r;
    }
    inline void qry(ll x1, ll y1, ll x2, ll y2) {
    	e[++tot] = {1,x2,y2};
    	e[++tot] = {1,x1-1,y1-1};
    	e[++tot] = {2,x1-1,y2};
    	e[++tot] = {2,x2,y1-1};
    	b[++*b]=y2, b[++*b]=y1-1;
    }
    inline void ins(int x, int y) {
    	e[++tot] = {0,x,y};
    }
    
    void merge(int l, int r) {
    	if (l==r) return;
    	merge(l,mid),merge(mid+1,r);
    	int now = l;
    	REP(i,mid+1,r) {
    		while (now<=mid&&e[now].x<=e[i].x) {
    			if (e[now].type==0) add(e[now].y,1);
    			++now;
    		}
    		if (e[i].type==1) ans+=qry(e[i].y);
    		else if (e[i].type==2) ans-=qry(e[i].y);
    	}
    	while (now!=l) {
    		if (e[--now].type==0) add(e[now].y,-1);
    	}
    	inplace_merge(e+l,e+mid+1,e+r+1);
    }
    
    int main() {
    	REP(i,1,n) {
    //		qry();
    //		ins();
    	}
    	sort(b+1,b+1+*b),*b=unique(b+1,b+1+*b)-b-1;
    	REP(i,1,tot) e[i].y=lower_bound(b+1,b+1+*b,e[i].y)-b;
    	merge(1,tot);
    	printf("%lld
    ", ans);
    }
    
  • 相关阅读:
    input file 上传图片并显示
    关于npm ---- npm 命令行运行多个命令
    webpack4.x 配置
    React的生命周期
    HTML5 meta 属性整理
    css 命名规范
    html5 标签 meter 和 progress
    .NET Linq TO XML 操作XML
    .NET 字符串指定规则添加换行
    Linux Centos上部署ASP.NET网站
  • 原文地址:https://www.cnblogs.com/uid001/p/10828193.html
Copyright © 2011-2022 走看看