CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)茶颜悦色(扫描线)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
const double pi = acos(-1);
const int maxn = 2e5 + 10;
const int maxm = (maxn<<5) + 5;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
int n, k, cnt, ans;
struct node{
    int x, ly, ry, flag;
    friend bool operator < (node a, node b){
        return a.x == b.x ? a.flag > b.flag : a.x < b.x;
    }
}line[maxn];
int Y[maxn], mx[maxn<<2], lazy[maxn<<2];
void pushdown(int rt){
    if(lazy[rt]){
        lazy[rt<<1] += lazy[rt]; lazy[rt<<1|1] += lazy[rt];
        mx[rt<<1] += lazy[rt]; mx[rt<<1|1] += lazy[rt];
        lazy[rt] = 0;
    }
}
void update(int rt, int l, int r, int L, int R, int val){
    if(L <= l && r <= R){
        mx[rt] += val;
        lazy[rt] += val;
        return;
    }
    pushdown(rt);
    int mid = (l + r) >> 1;
    if(L <= mid) update(lson, L, R, val);
    if(R > mid) update(rson, L, R, val);
    mx[rt] = max(mx[rt<<1], mx[rt<<1|1]);
}
int main()
{
    //freopen("E://one.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
    //freopen("E://oneout.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
    int x, y;
    scanf("%d %d", &n, &k);
    for(int i = 1 ; i <= n ; ++ i){
        scanf("%d %d", &x, &y);
        line[++cnt] = node{x, y, y + k, 1};
        Y[cnt] = y;
        line[++cnt] = node{x + k, y, y + k, -1};
        Y[cnt] = y + k;
    }
    sort(Y + 1, Y + 1 + cnt);
    int len = unique(Y + 1, Y + 1 + cnt) - Y - 1;
    sort(line + 1, line + 1 + cnt);
    for(int i = 1 ; i <= cnt ; ++ i){
        int l = lower_bound(Y + 1, Y + 1 + len, line[i].ly) - Y;
        int r = lower_bound(Y + 1, Y + 1 + len, line[i].ry) - Y;
        //cout << l << ' ' <<r <<endl;
        update(1, 1, len, l, r, line[i].flag);
        //cout << mx[1] << endl;
        ans = max(ans, mx[1]);
    }
    cout << ans;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值