/* -*- coding: utf-8 -*- * * 1490.cc: No.1490 スライムと爆弾 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_H = 2000; const int MAX_W = 2000; const int MAX_N = 100000; const int MAX_M = 100000; /* typedef */ typedef long long ll; struct Slime { int y0, y1, x0, x1, a; Slime() {} void read() { scanf("%d%d%d%d%d", &y0, &y1, &x0, &x1, &a); y0--, x0--; } }; /* global variables */ Slime sls[MAX_N]; ll cs[MAX_H + 2][MAX_W + 2]; /* subroutines */ /* main */ int main() { int h, w, n, m; scanf("%d%d%d%d", &h, &w, &n, &m); for (int i = 0; i < n; i++) sls[i].read(); for (int i = 0; i < m; i++) { int y, x, b, c; scanf("%d%d%d%d", &y, &x, &b, &c); int y0 = max(1, y - b), x0 = max(1, x - b); int y1 = min(h + 1, y + b + 1), x1 = min(w + 1, x + b + 1); cs[y0][x0] += c; cs[y0][x1] -= c; cs[y1][x0] -= c; cs[y1][x1] += c; } for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) cs[y + 1][x + 1] += cs[y + 1][x] + cs[y][x + 1] - cs[y][x]; for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) cs[y + 1][x + 1] += cs[y + 1][x] + cs[y][x + 1] - cs[y][x]; //for (int y = 1; y <= h; y++) //for (int x = 1; x <= w; x++) //printf("%d%c", cs[y][x], (x < w) ? ' ' : '\n'); int cnt = 0; for (int i = 0; i < n; i++) { Slime &sli = sls[i]; ll sum = cs[sli.y1][sli.x1] - cs[sli.y1][sli.x0] - cs[sli.y0][sli.x1] + cs[sli.y0][sli.x0]; if (sli.a > sum) cnt++; } printf("%d\n", cnt); return 0; }