#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f
#define maxn 32000 + 50
#define juzheng 300
#define ll long long
using namespace std;
//Date:2017-9-3
//Author:HarryBlackCat
int n,tree[maxn],lv[maxn],x,y;
int lowbit(int t){
return t & (-t);
}
void add(int index,int val){
for(int i = index;i <= maxn;i += lowbit(i))
tree[i] += val;
}
int get_sum(int index){
int ans = 0;
for(int i = index;i > 0;i -= lowbit(i))
ans += tree[i];
return ans;
}
void init(){
memset(lv,0,sizeof(lv));
memset(tree,0,sizeof(tree));
}
int main(){
while(cin >> n){
init();
for(int i = 1;i <= n;i++){
cin >> x >> y;
x++;//注意横坐标x是可以取0的求和时会TLE所以要每个数+1表示
lv[get_sum(x)]++;//计算等级
add(x,1);
}
for(int i = 0;i < n;i++)
cout << lv[i] << endl;
}
return 0;
}
HDU 1541 Stars(树状数组-水题,模板题)
最新推荐文章于 2021-07-30 08:31:17 发布