POJ_2352_Stars

#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;
}

你可能感兴趣的:(tree,poj,segment)