记录编号 393390 评测结果 AAAAAAAAAAAAAAA
题目名称 256.[POI 2001] 金矿 最终得分 100
用户昵称 confoo 是否通过 通过
代码语言 C++ 运行时间 0.198 s
提交时间 2017-04-10 22:05:29 内存使用 2.27 MiB
显示代码纯文本
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cctype>
#define lch (o<<1)
#define rch ((o<<1)|1)
#define mid ((l + r)>>1)
namespace I {
	const int L = 1 << 15 | 1;
	char *s, *t, buf[L];
	inline char gc() {
		if (s == t) t = (s = buf) + fread(buf, 1, L, stdin);
		return *s++;
	}
	inline int gi() {
		int ch = gc(), r = 0, f = 1;
		while (!isdigit(ch)) {
			if (ch == '-') f = -1;
			ch = gc();
		}
		while (isdigit(ch)) r = r*10 + ch - '0', ch = gc();
		return r*f;
	}
}using I::gi;
const int W = 6e4 + 10, DEL = 3e4, N = 15e3 + 10;
typedef std::pair<int, int> pa;
int n, w, h, ans, mx[W << 2], adv[W << 2];
pa st[N];
inline void mkad(int o, int v) {if (o) mx[o] += v, adv[o] += v;}
void down(int o) {
	if (o) mkad(lch, adv[o]), mkad(rch, adv[o]), adv[o] = 0;
}
void add(int o, int l, int r, int q1, int q2, int q3) {
	if (q1 <= l && r <= q2) mkad(o, q3), ans = std::max(ans, mx[o]);
	else {
		down(o);
		if (q1 <= mid) add(lch, l, mid, q1, q2, q3);
		if (mid < q2) add(rch, mid + 1, r, q1, q2, q3);
		mx[o] = std::max(mx[lch], mx[rch]);
		ans = std::max(ans, mx[o]);
	}
}
int main() {
	freopen("kop.in", "r", stdin);
	freopen("kop.out", "w", stdout);
	w = gi(), h = gi(), n = gi();
	for (int i = 1, x, y; i <= n; i++) x = gi(), y = gi(), st[i] = std::make_pair(x + DEL, y + DEL);
	std::sort(st + 1, st + 1 + n);
	for (int i = 1, j = 0; i <= n; i++) {
		while (j + 1 <= n && st[j + 1].first < st[i].first - w) ++j, add(1, 0, DEL<<1, st[j].second, st[j].second + h, -1);
		add(1, 0, DEL<<1, st[i].second, st[i].second + h, 1);
	}
	printf("%d\n", ans);
}