線段樹(shù)和樹(shù)狀數(shù)組都可以用
#include <stdio.h>
#include <stdlib.h>

const int LEN = 15005;

//坐標(biāo)處理
struct NODE


{
int x; //X坐標(biāo)
int y; //Y坐標(biāo)
int addr; //第幾個(gè)點(diǎn)
}node[LEN];

int cmp ( const void *a, const void *b )


{

int ans = ( (NODE *)a )->x-( (NODE *)b )->x;
if ( !ans )

{
ans = ( (NODE *)a )->y-( (NODE *)b )->y;
}
return ans;
}

//記錄答案的數(shù)組
int answer[LEN];

//線段樹(shù)
struct


{
int num; //區(qū)間中點(diǎn)的個(gè)數(shù)
int b, e; //左右區(qū)間
int lson, rson; //左右孩子
}tree[LEN*25];
int next_tree;

void creat ( int b, int e ) //建樹(shù)


{

int p = next_tree;
next_tree ++;
tree[p].b = b;
tree[p].e = e;
tree[p].lson = -1;
tree[p].rson = -1;
tree[p].num = 0;

if ( b!=e )

{
tree[p].lson = next_tree;
creat ( b, (b+e)/2 );

tree[p].rson = next_tree;
creat ( (b+e)/2+1, e );
}
}

void ins ( int p, int key ) //插入一個(gè)結(jié)點(diǎn)


{

if ( tree[p].b==tree[p].e )

{
tree[p].num ++;
}
else

{
int mid = ( tree[p].b+tree[p].e )/2;
if ( key>mid )

{
ins ( tree[p].rson, key );
}
else

{
ins ( tree[p].lson, key );
}
tree[p].num = tree[ tree[p].lson ].num+tree[ tree[p].rson ].num;
}
}

int ser ( int p, int key ) //查找函數(shù)


{

if ( tree[p].b==tree[p].e )

{
return tree[p].num;
}
else

{
int mid = ( tree[p].b+tree[p].e )/2;
if ( key>mid )

{
return tree[ tree[p].lson ].num + ser ( tree[p].rson, key );
}
else

{
return ser ( tree[p].lson, key );
}
}
}

void work ( int n, int max ) //主要的工作函數(shù)


{

next_tree = 0;
for ( int i=0; i<n; i++ )

{
answer[i] = 0;
}

qsort ( node, n, sizeof ( NODE ), cmp );
creat ( 0, max );
for ( int i=0; i<n; i++ )

{
int addr = ser ( 0, node[i].y );
answer[addr] ++ ;
ins ( 0, node[i].y );
}
}

int main ()


{

int n;
int max = -1;;
scanf ( "%d", &n );
for ( int i=0; i<n; i++ )

{
scanf ( "%d%d", &node[i].x, &node[i].y );
node[i].addr = i;
if ( node[i].y>max )

{
max = node[i].y;
}
}

work ( n, max );
for ( int i=0; i<n; i++ )

{
printf ( "%d\n", answer[i] );
}
}
