#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct BIT2DRangeAdd { BIT2DRangeAdd(int height_, int width_, const Abelian ID = 0) : height(height_), width(width_), ID(ID) { ++height; ++width; dat_const.assign(height, std::vector(width, ID)); dat_linear[0].assign(height, std::vector(width, ID)); dat_linear[1].assign(height, std::vector(width, ID)); dat_quadratic.assign(height, std::vector(width, ID)); } void add(int y1, int x1, int y2, int x2, const Abelian val) { ++y1; ++x1; ++y2; ++x2; for (int i = y1; i < height; i += i & -i) for (int j = x1; j < width; j += j & -j) { dat_const[i][j] += val * (y1 - 1) * (x1 - 1); dat_linear[0][i][j] -= val * (x1 - 1); dat_linear[1][i][j] -= val * (y1 - 1); dat_quadratic[i][j] += val; } for (int i = y1; i < height; i += i & -i) for (int j = x2 + 1; j < width; j += j & -j) { dat_const[i][j] -= val * (y1 - 1) * x2; dat_linear[0][i][j] += val * x2; dat_linear[1][i][j] += val * (y1 - 1); dat_quadratic[i][j] -= val; } for (int i = y2 + 1; i < height; i += i & -i) for (int j = x1; j < width; j += j & -j) { dat_const[i][j] -= val * y2 * (x1 - 1); dat_linear[0][i][j] += val * (x1 - 1); dat_linear[1][i][j] += val * y2; dat_quadratic[i][j] -= val; } for (int i = y2 + 1; i < height; i += i & -i) for (int j = x2 + 1; j < width; j += j & -j) { dat_const[i][j] += val * y2 * x2; dat_linear[0][i][j] -= val * x2; dat_linear[1][i][j] -= val * y2; dat_quadratic[i][j] += val; } } Abelian sum(int y, int x) const { ++y; ++x; Abelian quad = ID, cons = ID, line[2] = {ID, ID}; for (int i = y; i > 0; i -= i & -i) for (int j = x; j > 0; j -= j & -j) { quad += dat_quadratic[i][j]; line[0] += dat_linear[0][i][j]; line[1] += dat_linear[1][i][j]; cons += dat_const[i][j]; } return quad * y * x + line[0] * y + line[1] * x + cons; } Abelian sum(int y1, int x1, int y2, int x2) const { return y1 <= y2 && x1 <= x2 ? sum(y2, x2) - sum(y2, x1 - 1) - sum(y1 - 1, x2) + sum(y1 - 1, x1 - 1) : ID; } private: int height, width; const Abelian ID; std::vector> dat_const, dat_quadratic; std::vector> dat_linear[2]; }; int main() { int h, w, n, m; cin >> h >> w >> n >> m; vector t(n), u(n), l(n), r(n), a(n); REP(i, n) cin >> t[i] >> u[i] >> l[i] >> r[i] >> a[i], --t[i], --u[i], --l[i], --r[i]; BIT2DRangeAdd bit(h, w); while (m--) { int x, y, b, c; cin >> x >> y >> b >> c; --x; --y; bit.add(max(x - b, 0), max(y - b, 0), min(x + b, h - 1), min(y + b, w - 1), c); } int ans = 0; REP(i, n) ans += bit.sum(t[i], l[i], u[i], r[i]) < a[i]; cout << ans << '\n'; return 0; }