标签:
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13421 | Accepted: 4442 |
Description
Input
Output
Sample Input
3 1 2 0 3 3 4 0
Sample Output
1 0 0
Hint
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<cstdlib> using namespace std; #define N 100010 int c[N],val[N]; struct node { int x,y,id; }e[N]; bool cmp(node a,node b) { if(a.y!=b.y) return a.y>b.y; return a.x<b.x; } int lowbit(int x) { return x&(-x); } void update(int pos,int m) { while(pos<N) { c[pos]+=m; pos+=lowbit(pos); } } int sum(int x) { int sum=0; while(x>0) { sum+=c[x]; x=x-lowbit(x); } return sum; } int main() { int n; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) { scanf("%d%d",&e[i].x,&e[i].y); e[i].x++,e[i].y++; e[i].id=i; } sort(e+1,e+1+n,cmp); val[e[1].id]=sum(e[1].x); update(e[1].x,1); for(int i=2;i<=n;i++) { if(e[i].x==e[i-1].x&&e[i].y==e[i-1].y) val[e[i].id]=val[e[i-1].id]; else val[e[i].id]=sum(e[i].x); update(e[i].x,1); } printf("%d",val[1]); for(int i=2;i<=n;i++) printf(" %d",val[i]); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4256216.html