标签:des blog http io ar os sp for strong
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13128 | Accepted: 4360 |
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
Source
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<cstdlib> #include<queue> #include<vector> using namespace std; #define N 1000010 #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 int n,num[N*4],sum[N*4]; struct line { int x,y,nt; }e[N]; bool cmp(line a,line b) { if(a.x==b.x) return a.y>b.y; return a.x<b.x; } int update(int l,int r,int rt,int L,int R) { if(L<=l&&r<=R) return sum[rt]; int m=(l+r)>>1; int ret=0; if(L<=m) ret+=update(lson,L,R); if(R>m) ret+=update(rson,L,R); return ret; } void push(int l,int r,int rt,int x) { sum[rt]++; if(l==r) return ; int m=(l+r)>>1; if(m>=x) push(lson,x); else push(rson,x); } int main() { while(scanf("%d",&n),n) { memset(sum,0,sizeof(sum)); memset(num,0,sizeof(num)); for(int i=1;i<=n;i++) { scanf("%d%d",&e[i].x,&e[i].y); e[i].nt=i; } sort(e+1,e+1+n,cmp); for(int i=1;i<=n;i++) { if(i!=1&&e[i].x==e[i-1].x&&e[i].y==e[i-1].y) num[e[i].nt]=num[e[i-1].nt]; else num[e[i].nt]=update(1,N,1,e[i].y,N); push(1,N,1,e[i].y); } for(int i=1;i<=n-1;i++) printf("%d ",num[i]); printf("%d\n",num[n]); } return 0; }
标签:des blog http io ar os sp for strong
原文地址:http://www.cnblogs.com/a972290869/p/4101083.html