//https://codeforces.com/contest/1184/problem/C2
#include<bits/stdc++.h>
#include<unordered_map>
#include<array>
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int N = 3e5 + 5;
int n, r, tot, ans;
struct Line {
int x, y, type;
bool operator < (Line& a)
{
if (y != a.y)
return y < a.y;
if (type == a.type)
return x < a.x;
return type > a.type;
}
}line[N];
struct SegTree {
struct node {
int l, r, mx, lazy;
}tree[4000000 * 4];
void push_up(int p) {
tree[p].mx = max(tree[p << 1].mx, tree[p << 1 | 1].mx);
}
void push_down(int p)
{
if (!tree[p].lazy)
return;
tree[p << 1].lazy += tree[p].lazy;
tree[p << 1 | 1].lazy += tree[p].lazy;
tree[p << 1].mx += tree[p].lazy;
tree[p << 1 | 1].mx += tree[p].lazy;
tree[p].lazy = 0;
}
void build(int l, int r, int p)
{
tree[p].l = l;
tree[p].r = r;
tree[p].lazy = 0;
if (l == r)
return;
int mid = (l + r) / 2;
build(l, mid, p << 1);
build(mid + 1, r, p << 1 | 1);
}
void update(int ul, int ur, int val, int p)
{
int l = tree[p].l, r = tree[p].r;
if (ul <= l && r <= ur)
{
tree[p].mx += val;
tree[p].lazy += val;
return;
}
push_down(p);
int mid = (l + r) / 2;
if (ul <= mid)
update(ul, ur, val, p << 1);
if (ur > mid)
update(ul, ur, val, p << 1 | 1);
push_up(p);
}
int query(int ql, int qr, int p)
{
int l = tree[p].l, r = tree[p].r;
if (ql <= l && qr >= r)
return tree[p].mx;
push_down(p);
int mid = (l + r) / 2;
int ans = 0;
if (ql <= mid)
ans = max(ans, query(ql, qr, p << 1));
if (qr > mid)
ans = max(ans, query(ql, qr, p << 1 | 1));
return ans;
}
}sg;
int gety(int x, int y)坐标轴旋转角度为a, x2 = xcosa + ysina, y2 = -xsina + ycosa
{
return y - x;
}
int getx(int x, int y)
{
return x + y;
}
void solve()
{
cin >> n >> r;
r *= 2;
for (int i = 1, x, y; i <= n; i++)
{
cin >> x >> y;
line[++tot].y = gety(x, y) + 2e6;
line[tot].x = getx(x, y) + 2e6;
line[tot].type = 1;
line[++tot].y = gety(x, y) + 2e6 + r;
line[tot].x = getx(x, y) + 2e6;
line[tot].type = -1;
}
sort(line + 1, line + 1 + tot);
sg.build(1, 4e6, 1);
for (int i = 1; i <= tot; i++)
{
sg.update(line[i].x, min(line[i].x + r, (int)4e6), line[i].type, 1);
ans = max(ans, sg.query(max(1, line[i].x - r), min(line[i].x + r, (int)4e6), 1));
}
cout << ans << '\n';
}
signed main()
{
IOS;
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}
坐标系旋转 + 扫描线(一个长宽固定的矩阵最多覆盖多少点)
最新推荐文章于 2024-10-14 09:08:48 发布