#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<bitset>
#include<map>
#pragma warning(disable:4996)
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::map;
class BIT
{
private:
vector<int>tree;
public:
BIT(){}
BIT(const int &size)
{
tree.resize(size);
}
int lowbit(const int &x)
{
return x&-x;
}
void add(int i,const int &value)
{
for (; i < tree.size(); i += lowbit(i))
{
tree[i] += value;
}
}
int sum(int i)
{
int ret = 0;
for (; i; i -= lowbit(i))
{
ret += tree[i];
}
return ret;
}
};
int main()
{
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n;
while (scanf("%d",&n)!=EOF)
{
BIT value(33000);
vector<int>star(n);
for (int i = 0; i < n; i++)
{
int x, y; scanf("%d%d",&x,&y);
star[value.sum(x+1)]++;
value.add(x + 1, 1);
}
for (int i = 0; i < n; i++)
{
printf("%d\n", star[i]);
}
}
return 0;
}POJ_2352_Stars
最新推荐文章于 2022-01-12 16:17:07 发布
本文介绍了一种利用Binary Indexed Tree (BIT) 数据结构解决区间查询与更新问题的方法。通过具体的代码实现,展示了如何构建BIT并进行元素的添加与求和操作,特别适用于离线处理大量查询与更新操作的场景。
432

被折叠的 条评论
为什么被折叠?



