'commit'
This commit is contained in:
36
TangDou/AcWing/BIT/POJ2352.cpp
Normal file
36
TangDou/AcWing/BIT/POJ2352.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user