poj 2352

来源:互联网 发布:德力西选型软件 编辑:程序博客网 时间:2024/06/05 18:13

题目:http://poj.org/problem?id=2352


树状数组,模版题。。直接按给定的顺序统计比当前X小于等于的星星个数即可。


#include <cmath>#include <ctime>#include <iostream>#include <string>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#include <map>#include <set>#include <algorithm>#include <cctype>#include <stack>#include <deque>using namespace std;typedef long long LL;#define EPS 10e-9#define INF 0x3f3f3f3f#define REP(i,n) for(int i=0; i<(n); i++)const int maxn = 40000;int c[maxn];int ans[maxn];int lowbit(int x)  {    return x&-x;}void add(int x){    while(x<maxn){        c[x]+=1;   x+=lowbit(x);    }}int sum(int x){    int ret=0;    while(x>0){       ret+=c[x];  x-=lowbit(x);    }    return ret;}int main(){    int n,x,y;    while(scanf("%d",&n)!=EOF){        memset(ans,0,sizeof(ans));        for(int i=0;i<n;i++){             scanf("%d %d",&x,&y);             x++;y++;             ans[ sum(x)]++;             add(x);        }        for(int i=0;i<n;i++)        printf("%d\n",ans[i]);    }   return 0;}

原创粉丝点击