2017ecjtu-summer training #4 UESTC 1584

此题链接 http://acm.uestc.edu.cn/#/problem/show/1584

此题和hdu1541几乎完全一样,我们要先对坐标排序,再进行操作。

hdu1541题解 http://www.cnblogs.com/stranger-/p/7157899.html

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std;
int c[maxn*2];
int k[maxn];
struct node
{
    int x,y;
}point[maxn];
bool cmp(const node &a,const node &b)
{
    if(a.y==b.y)
        return a.x<b.x;
    return a.y<b.y;
}
int lowbit(int x)
{
    return x&(-x);
}
int getsum(int x)
{
    int ans=0;
    while(x>0)
    {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}
void add(int x,int y)
{
    while(x<maxn)
    {
        c[x]+=y;
        x+=lowbit(x);
    }
}
int main()
{
        int n;
        int x,y;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
           scanf("%d%d",&point[i].x,&point[i].y);
        }
        sort(point,point+n,cmp);
        for(int i=0;i<n;i++)
        {
            k[getsum(point[i].x)]++;
            add(point[i].x,1);
        }
        for(int i=0;i<n;i++)
           printf("%d
",k[i]);
        return 0;
}
原文地址:https://www.cnblogs.com/stranger-/p/7158390.html