hdoj1541
Problem : 1541 ( Stars ) Judge Status : Accepted
RunId : 2816947 Language : C++ Author : huwenbiao
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
RunId : 2816947 Language : C++ Author : huwenbiao
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
/***************************************************************\
*Author:Hu Wenbiao
*Created Time: Sat 14 Aug 2010 10:01:51 AM CST
*File Name: main.cpp
*Description:树状数组。因为y是升序的,从前往后一个一个地计算各
*星星,只用x座标即可。
\***************************************************************/
//*========================*Head File*========================*\\
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/*----------------------*Global Variable*----------------------*/
//#define lowbit(i) i&(-i);
int C[32100],level[15100],N,x,_max;
//*=======================*Main Program*=======================*//
using namespace std;
int lowbit(int i){
return i&(-i);
}
int sum(int i){
int sum=0;
while(i>0){
sum+=C[i];
i-=lowbit(i);
}
return sum;
}
void add(int i,int diff){
while(i<=_max){
C[i]+=diff;
i+=lowbit(i);
}
}
int main(){
//freopen("input","r",stdin);
_max=32001;
while(scanf("%d",&N)!=EOF){
memset(C,0,sizeof(C));
memset(level,0,sizeof(level));
for(int i=0;i<N;i++){
scanf("%d%*d",&x);
x++;//座标要加1,因为座标为0时add(int i,int diff)会出问题
level[sum(x)]++;
add(x,1);
}
for(int i=0;i<N;i++)
printf("%d\n",level[i]);
}
}