内容纲要

POJ2352
file

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define M 1000000007
using namespace std;
typedef long long LL;
const int maxn = 4e5+6;

int n;
int bit[maxn],lev[maxn];

int lowbit(int x)
{
    return x & (-x);
}

int update(int pos,int x)
{
    for(int i = pos;i <= maxn;i += lowbit(i))
        bit[i] += x;
}

int query(int pos)
{
    int sum = 0;
    for(int i = pos;i > 0;i -= lowbit(i))
        sum += bit[i];
    return sum;
}

int main()
{
    int x,y;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d%d", &x, &y);
        lev[query(++x)]++;
        update(x,1);
    }
    for(int i = 0;i <= n-1;i++)
        printf("%d\n",lev[i]);

    return 0;
}

file


树状数组教程:传送门

发表评论

电子邮件地址不会被公开。 必填项已用*标注