[BZOJ 1818] CQOI2010 内部白点

来源:互联网 发布:apache 设置访问目录 编辑:程序博客网 时间:2024/06/08 18:29

这里写图片描述

处理方式酷似上一题…简化版?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;}
0 0