问题要求统计左下角(x,y均小于当前star的star)有0颗星星、1颗星星.……n-1颗星星的星星个数,顺序输出。题目中给的数据是按y从小到大,所以对于star i(xi,yi),可能在它左下角的star(y<yi)肯定已经出现过了,用树状数组统计star i前有多少颗star 满足x<xi,累加就行了。star坐标可能有0,记得+1.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#define DEBUG
#define LL long long
#define maxn 33000
using namespace std;
int fin[maxn/2];
int tree[maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int pos,int num,int n)
{
while(pos<=n)
{
tree[pos]+=num;
pos+=lowbit(pos);
}
}
int getsum(int en)
{
int sum=0;
while(en>0)
{
sum+=tree[en];
en-=lowbit(en);
}
return sum;
}
int main()
{
int n;
scanf("%d",&n);
memset(tree,0,sizeof(tree));
for(int i=0;i<n;++i)
{
int x,y;
scanf("%d%d",&x,&y);
fin[getsum(x+1)]++;
update(x+1,1,maxn);
}
for(int i=0;i<n;++i)
{
printf("%d\n",fin[i]);
}
}