[BZOJ 1818] CQOI2010 内部白点

这里写图片描述

处理方式酷似上一题…简化版?hhhhhhhhh

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 100010 ;
inline void read(int &x)
{
    char c; bool f = 0;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') f = 1;
    for (x = c - '0'; (c = getchar()) >= '0' && c <= '9'; x = x * 10 + c - '0');
    if (f) x = -x;
}

struct Data
{
    int x, y;

    inline bool operator < (const Data & b) const 
    {
        return y < b.y || (y == b.y && x < b.x);
    }
}p[N];

int tx[N], ty[N], cx, cy;
int cnt[N], n;
bool vis[N];

namespace BIT
{
    int c[N];

    inline void add(int p, int v)
    {
        while (p <= cx) c[p] += v, p += p & -p;
    }
    inline int ask(int p)
    {
        int ret = c[p];
        while (p -= p & -p) ret += c[p];
        return ret;
    }
}

int main()
{
    read(n);
    for (int i = 1; i <= n; ++i)
    {
        read(p[i].x), read(p[i].y);
        tx[i] = p[i].x, ty[i] = p[i].y;
    }

    sort(tx + 1, tx + n + 1);
    cx = unique(tx + 1, tx + n + 1) - tx - 1;
    sort(ty + 1, ty + n + 1);
    cy = unique(ty + 1, ty + n + 1) - ty - 1;
    sort(p + 1, p + n + 1);

    for (int i = 1; i <= n; ++i)
    {
        p[i].x = lower_bound(tx + 1, tx + cx + 1, p[i].x) - tx;
        p[i].y = lower_bound(ty + 1, ty + cy + 1, p[i].y) - ty;
        cnt[p[i].x]++;
    }

    using namespace BIT;
    int ans = n, cur = 1;
    p[n + 1].y = -1;

    while (cur <= n)
    {
        int l = cur;
        while (p[l].y == p[l + 1].y) ans += ask(p[l + 1].x - 1) - ask(p[l].x), l++;
        while (cur <= l) 
        {
            int x = p[cur++].x; cnt[x]--;
            if (!vis[x] && cnt[x]) vis[x] = 1, add(x, 1);
            else if (vis[x] && !cnt[x]) add(x, -1);
        }
    }

    printf("%d\n", ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值