樹狀數組,模版題。。直接按給定的順序統計比當前X小於等於的星星個數即可。
[cpp]
#include <cmath>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
#include <stack>
#include <deque>
using namespace std;
typedef long long LL;
#define EPS 10e-9
#define INF 0x3f3f3f3f
#define REP(i,n) for(int i=0; i<(n); i++)
const int maxn = 40000;
int c[maxn];
int ans[maxn];
int lowbit(int x) {
return x&-x;
}
void add(int x){
while(x<maxn){
c[x]+=1; x+=lowbit(x);
}
} www.2cto.com
int sum(int x){
int ret=0;
while(x>0){
ret+=c[x]; x-=lowbit(x);
}
return ret;
}
int main(){
int n,x,y;
while(scanf("%d",&n)!=EOF){
memset(ans,0,sizeof(ans));
for(int i=0;i<n;i++){
scanf("%d %d",&x,&y);
x++;y++;
ans[ sum(x)]++;
add(x);
}
for(int i=0;i<n;i++)
printf("%d\n",ans[i]);
}
return 0;
}