坐标系旋转 + 扫描线(一个长宽固定的矩阵最多覆盖多少点)

//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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值