Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 140005;
- int i, j, k, h, w, n, rs, x, y, ans[4 * N], totalSum[4 * N];
- pair<int, int> a[N];
- int goToNext(int x, int i) {
- for(++i; i <= n && a[i].first == x; ++i);
- return i;
- }
- void update(int left, int right, int nod) {
- if(left == right) {
- totalSum[nod] += y;
- ans[nod] = totalSum[nod];
- } else {
- int pivot = (left + right) / 2;
- if(x <= pivot) update(left, pivot, 2 * nod);
- else update(pivot + 1, right, 2 * nod + 1);
- totalSum[nod] = totalSum[2 * nod] + totalSum[2 * nod + 1];
- ans[nod] = max(ans[2 * nod], totalSum[2 * nod] + ans[2 * nod + 1]);
- }
- }
- int main() {
- freopen("mine.in", "r", stdin);
- freopen("mine.out", "w", stdout);
- scanf("%d %d %d", &h, &w, &n);
- for(i = 1; i <= n; ++i) scanf("%d %d", &a[i].first, &a[i].second), a[i].first += 30001, a[i].second += 30001;
- sort(a + 1, a + n + 1);
- for(j = i = 1; i <= n; ++i) {
- x = 2 * a[i].second - 1; y = 1; update(1, N - 1, 1);
- x = 2 * (a[i].second + w); y = -1; update(1, N - 1, 1);
- while(a[i].first - a[j].first > h) {
- x = 2 * a[j].second - 1; y = -1; update(1, N - 1, 1);
- x = 2 * (a[j].second + w); y = 1; update(1, N - 1, 1);
- ++j;
- }
- rs = max(rs, ans[1]);
- }
- printf("%d\n", rs);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement