2481

/*
答案就在一念之间
*/
// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef long long LL;
typedef unsigned long long ULL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define FORi(a,b,c) for(int i=(a);i<(b);i+=c)
#define FORj(a,b,c) for(int j=(a);j<(b);j+=c)
#define FORk(a,b,c) for(int k=(a);k<(b);k+=c)
#define FORp(a,b,c) for(int p=(a);p<(b);p+=c)
#define FORii(a,b,c) for(int ii=(a);ii<(b);ii+=c)
#define FORjj(a,b,c) for(int jj=(a);jj<(b);jj+=c)
#define FORkk(a,b,c) for(int kk=(a);kk<(b);kk+=c)

#define FF(i,a)    for(int i=0;i<(a);i++)
#define FFD(i,a)   for(int i=(a)-1;i>=0;i--)

#define Z(a) (a<<1)
#define Y(a) (a>>1)

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}


// code begin
struct node
{
	int x;
	int y;
	int dx;
	friend bool operator<(node a,node b)
	{
		if(a.y==b.y)
			return a.x<b.x;
		return a.y<b.y;
	}
};
node D[100010];
int ans[100010];
int Bit[100010];
int N,Nx;

inline int lowBit(int x)
{
	return x&(-x);
}

int getSum(int x)
{
	int ans = 0;
	/*
	for(int i=x;i>0;i-=lowBit(i))
	{
		ans += Bit[i];
	}
	*/
	while(x>0)
	{
		ans+=Bit[x];
		x-=lowBit(x);
	}
	return ans;
}

void update(int x,int c)
{
	/*
	for(int i=x;i<Nx;i+=lowBit(i))
	{
		Bit[i]+=c;
	}
	*/
	while(x<Nx)
	{
		Bit[x]+=c;
		x+=lowBit(x);
	}
}

int main()
{
	read;
	write;
	char in[50];
	while(scanf("%d",&N)==1)
	{
		if(!N) break;
		getchar();
		Nx = 0;
		FORi(0,N,1)
		{
			gets(in);
			sscanf(in,"%d %d",&D[i].x,&D[i].y);
			D[i].x++;
			D[i].y = 100000-D[i].y;
			D[i].dx = i;
			if(D[i].x>Nx)
				Nx = D[i].x;
		}
		Nx++;
		sort(D,D+N);
		memset(ans,0,sizeof(ans));
		memset(Bit,0,sizeof(Bit));
		ans[D[0].dx] = getSum(D[0].x);
		update(D[0].x,1);
		FORi(1,N,1)
		{
			if(D[i].x==D[i-1].x && D[i].y==D[i-1].y)
			{
				ans[D[i].dx] = ans[D[i-1].dx];
				update(D[i].x,1);
			}
			else
			{
				ans[D[i].dx] = getSum(D[i].x);
				update(D[i].x,1);
			}
		}
		printf("%d",ans[0]);
		FORi(1,N,1)
		{
			printf(" %d",ans[i]);
		}
		printf("\n");
	}
	return 0;
}

posted @ 2011-04-13 10:31  AC2012  阅读(231)  评论(0编辑  收藏  举报