You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
using namespace std ;
const int N = 32010 ;
int cnt [ N ] ;
// 树状数组模板
# define lowbit(x) (x & -x)
typedef long long LL ;
int c [ N ] ;
void add ( int x , int v ) {
while ( x < N ) c [ x ] + = v , x + = lowbit ( x ) ;
}
LL sum ( int x ) {
LL res = 0 ;
while ( x ) res + = c [ x ] , x - = lowbit ( x ) ;
return res ;
}
int main ( ) {
int n ;
scanf ( " %d " , & n ) ;
for ( int i = 1 ; i < = n ; i + + ) {
int x , y ;
scanf ( " %d %d " , & x , & y ) ; // 这里的y没有用到,想想也是, 因为是扫描线是从下向上的, 与y的具体值无关
x + + ; // 树状数组存储从1开始, 所有x映射都+1。
add ( x , 1 ) ;
// 查询在x之前有多少个数字,也就是有多少个星星个数
cnt [ sum ( x ) ] + + ; // 找到了一个左下角有5个星星的, 那么5这个桶计数++,这是题意要求的
}
// 输出所有等级星星的个数
for ( int i = 1 ; i < = n ; i + + ) printf ( " %d \n " , cnt [ i ] ) ;
return 0 ;
}