BZOJ 1935 Tree 园丁的烦恼 [差分][树状数组]
2017-07-14 22:04
246 查看
#include<cstdio> #include<algorithm> using namespace std; #define N 500005 #define X 10000005 inline int in(int x=0,char ch=getchar()){while(ch>'9'||ch<'0') ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x;} struct Point{int x,y;}p ; struct Qus{int x,y,f,id;}q[N<<2]; inline bool operator < (const Point &a,const Point &b){return a.x<b.x;} inline bool operator < (const Qus &a,const Qus &b){return a.x<b.x||(a.x==b.x&&a.y<b.y);} int ans ;int n,m,cnt;int d[X]; inline void Add(int x){for(;x<X;x+=x&-x) d[x]++;} inline int Sum(int x,int res=0){for(;x;x-=x&-x) res+=d[x];return res;} int main(){ n=in(),m=in();int x1,y1,x2,y2; for(int i=1;i<=n;i++) p[i].x=in()+1,p[i].y=in()+1; for(int i=1;i<=m;i++){ x1=in()+1,y1=in()+1,x2=in()+1,y2=in()+1; q[++cnt]=(Qus){x1-1,y1-1,1,i}; q[++cnt]=(Qus){x1-1,y2,-1,i}; q[++cnt]=(Qus){x2,y1-1,-1,i}; q[++cnt]=(Qus){x2,y2,1,i}; } sort(p+1,p+n+1);sort(q+1,q+cnt+1); for(int i=1,j=1;i<=cnt;i++){ for(;j<=n&&p[j].x<=q[i].x;j++) Add(p[j].y); ans[q[i].id]+=Sum(q[i].y)*q[i].f; } for(int i=1;i<=m;i++) printf("%d\n",ans[i]); return 0; }
相关文章推荐
- BZOJ 1935: [Shoi2007]Tree 园丁的烦恼( 差分 + 离散化 + 树状数组 )
- BZOJ 1935: [Shoi2007]Tree 园丁的烦恼 [树状数组 离线 离散化]
- BZOJ 1935 Tree 园丁的烦恼 (树状数组)
- 【树状数组】bzoj1935 [Shoi2007]Tree 园丁的烦恼
- [BZOJ1935][SHOI2007]Tree 园丁的烦恼(离线+动态维护树状数组)
- 1935: [Shoi2007]Tree 园丁的烦恼 (树状数组)
- bzoj1935: [Shoi2007]Tree 园丁的烦恼
- [BZOJ1935][SHOI2007]Tree 园丁的烦恼(树状数组)
- BZOJ1935: [Shoi2007]Tree 园丁的烦恼
- bzoj 1935: [Shoi2007]Tree 园丁的烦恼
- BZOJ 1935: [Shoi2007]Tree 园丁的烦恼
- BZOJ 1935: [Shoi2007]Tree 园丁的烦恼
- Bzoj1935 [SHOI2007]Tree 园丁的烦恼
- bzoj 1935: [Shoi2007]Tree 园丁的烦恼
- [bzoj1935][Shoi2007]Tree 园丁的烦恼 _树状数组
- 【BZOJ】【P1935】【Shoi2007】【Tree 园丁的烦恼】【题解】【树状数组+离散化】
- 【bzoj 1935】【codevs 2342】[Shoi2007]Tree 园丁的烦恼(树状数组)
- [bzoj4822][Cqoi2017]老C的任务&[bzoj1935][Shoi2007]Tree 园丁的烦恼
- bzoj1935 [Shoi2007]Tree 园丁的烦恼 二维偏序
- 【bzoj 1935】Tree 园丁的烦恼(树状数组)