标签:div lower space ret fine 分享 ble owb 难题
#include<cstdio> #include<cstring> #include<algorithm> #define G *++ptr #define LL int using namespace std; char buf[40000007],*ptr=buf-1; const int M=1e6+7; int read(){ int x=0,f=1,c=G; while(c<48)c==‘-‘&&(f=-1),c=G; while(c>47)x=x*10+c-48,c=G; return x*f; } LL ans[M],s[3*M],xs[3*M]; int n,m,xp,qp,ep; int lowbit(int x){return x&-x;} void add(int x,LL v){ while(x<=xp){ s[x]+=v; x+=lowbit(x); } } LL query(int x){ LL ans=0; while(x>0){ ans+=s[x]; x-=lowbit(x); } return ans; } struct Q{ LL l,r,h,id,s; bool operator <(const Q& x)const{return h<x.h;} void calc(){ ans[id]+=(query(r)-query(l-1))*s; } }q[2*M]; struct pos{ LL x,y,w; bool operator <(const pos& h)const{return y<h.y;} void calc(){ add(x,w); } }e[M]; void $(LL &x){x=lower_bound(xs+1,xs+xp+1,x)-xs;} int main() { fread(buf,1,sizeof(buf),stdin)[buf]=0; LL x,y,hx,hy; n=read(); m=read(); for(int i=1;i<=n;i++){ x=read(); y=read(); e[ep++]=(pos){xs[++xp]=x,y,1}; } sort(xs+1,xs+xp+1); for(int i=0;i<ep;i++) $(e[i].x); for(int i=1;i<=m;i++){ x=read(); y=read(); hx=read(); hy=read(); x=lower_bound(xs+1,xs+xp+1,x)-xs; hx=upper_bound(xs+1,xs+xp+1,hx)-xs-1; q[qp++]=(Q){x,hx,y-1,i,-1}; q[qp++]=(Q){x,hx,hy,i,1}; } sort(e,e+ep); sort(q,q+qp); for(int i=0,j=0;i<qp;i++){ while(j<ep&&e[j].y<=q[i].h) e[j++].calc(); q[i].calc(); } for(int i=1;i<=m;i++) printf("%d\n",ans[i]); return 0; }
bzoj1382 1935: [Shoi2007]Tree 园丁的烦恼
标签:div lower space ret fine 分享 ble owb 难题
原文地址:http://www.cnblogs.com/lyzuikeai/p/7348715.html