标签:size this min view scanf where div c++ operator
排序以后把在第二维上分治
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int N = 1e5+7; const int inf = 0x3f3f3f3f; const double eps = 1e-6; typedef long long ll; const ll mod = 1e9+7; struct node{ int x,y,id; friend bool operator < (node a,node b){ if(a.x!=b.x) return a.x<b.x; return a.y<b.y; } }p[N],a[N]; int f[N]; int ans[N]; void cdq(int l,int r){ if(l==r) return ; int mid=(l+r)>>1; cdq(l,mid); cdq(mid+1,r); int i=l,j=mid+1,cnt=l; while(i<=mid&&j<=r){ if(p[i].y<=p[j].y){ a[cnt++]=p[i++]; }else{ f[p[j].id]+=(i-l); a[cnt++]=p[j++]; } } while(i<=mid) a[cnt++]=p[i++]; while(j<=r){ f[p[j].id]+=(i-l); a[cnt++]=p[j++]; } for(int k=l;k<=r;k++) p[k]=a[k]; } int main(){ // ios::sync_with_stdio(false); // cin.tie(0); cout.tie(0); int n; while(~scanf("%d",&n)){ memset(f,0,sizeof(f)); memset(ans,0,sizeof(ans)); for(int i=1;i<=n;i++){ int x,y; scanf("%d%d",&x,&y); p[i]=node{x,y,i}; } sort(p+1,p+n+1); cdq(1,n); for(int i=1;i<=n;i++) ans[f[i]]++; for(int i=0;i<n;i++) printf("%d\n",ans[i]); } return 0; }
标签:size this min view scanf where div c++ operator
原文地址:https://www.cnblogs.com/wmj6/p/11477436.html