标签:des blog io ar os sp for on 文件
#include<cstdio> #include<iostream> #include<algorithm> #include<cstdlib> #define LL long long #define N 1000010 using namespace std; struct que{int x,y,rnk,opr;}q[5*N]; inline bool operator <(const que &a,const que &b){return a.x<b.x||a.x==b.x&&a.opr<b.opr;} int n,m,cnt,cnt2; int x[N],y[N],a[N],b[N],c[N],d[N]; int dat[3*N]; int ans[N][5]; int C[3*N]; inline LL read() { LL x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } inline int bsearch(int x) { int l=1,r=cnt; while (l<=r) { int mid=(l+r)>>1; if (x==dat[mid])return mid; if (x>dat[mid]){l=mid+1;} else r=mid-1; } } inline int lowbit(int x){return x&(-x);} inline int add(int x,int d) { for (int i=x;i<=cnt;i+=lowbit(i)) C[i]+=d; } inline int ask(int x) { int sum=0; for (int i=x;i;i-=lowbit(i)) sum+=C[i]; return sum; } int main() { n=read();m=read(); for(int i=1;i<=n;i++) { x[i]=read();y[i]=read(); dat[++cnt]=y[i]; } for (int i=1;i<=m;i++) { a[i]=read();b[i]=read();c[i]=read();d[i]=read(); dat[++cnt]=b[i];dat[++cnt]=d[i]; } sort(dat+1,dat+cnt+1); for (int i=1;i<=n;i++) { y[i]=bsearch(y[i]); q[++cnt2].x=x[i];q[cnt2].y=y[i]; } for (int i=1;i<=m;i++) { b[i]=bsearch(b[i]);d[i]=bsearch(d[i]); q[++cnt2].x=c[i];q[cnt2].y=d[i];q[cnt2].rnk=i;q[cnt2].opr=1; q[++cnt2].x=a[i]-1;q[cnt2].y=d[i];q[cnt2].rnk=i;q[cnt2].opr=2; q[++cnt2].x=c[i];q[cnt2].y=b[i]-1;q[cnt2].rnk=i;q[cnt2].opr=3; q[++cnt2].x=a[i]-1;q[cnt2].y=b[i]-1;q[cnt2].rnk=i;q[cnt2].opr=4; } sort(q+1,q+cnt2+1); for (int i=1;i<=cnt2;i++) { if (q[i].opr)ans[q[i].rnk][q[i].opr]=ask(q[i].y); else add(q[i].y,1); } for (int i=1;i<=m;i++) printf("%d\n",ans[i][1]+ans[i][4]-ans[i][2]-ans[i][3]); }
标签:des blog io ar os sp for on 文件
原文地址:http://www.cnblogs.com/zhber/p/4139089.html