// ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- fn run() { input! { h: usize, w: usize, n: usize, m: usize, slime: [(usize1, usize, usize1, usize, i64); n], bomb: [(usize1, usize1, usize, i64); m], } let mut dp = vec![vec![0; w + 1]; h + 1]; for (x, y, b, c) in bomb { let l = y.saturating_sub(b); let r = w.min(y + b + 1); let u = x.saturating_sub(b); let d = h.min(x + b + 1); dp[u][l] += c; dp[u][r] -= c; dp[d][l] -= c; dp[d][r] += c; } for i in 0..=h { for j in 0..=w { if i > 0 { dp[i][j] += dp[i - 1][j]; } if j > 0 { dp[i][j] += dp[i][j - 1]; } if i > 0 && j > 0 { dp[i][j] -= dp[i - 1][j - 1]; } } } for i in (0..=h).rev() { for j in (0..=w).rev() { if i < h { dp[i][j] += dp[i + 1][j]; } if j < w { dp[i][j] += dp[i][j + 1]; } if i < h && j < w { dp[i][j] -= dp[i + 1][j + 1]; } } } let mut ans = 0; for (u, d, l, r, a) in slime { let s = dp[u][l] - dp[u][r] - dp[d][l] + dp[d][r]; if s < a { ans += 1; } } println!("{}", ans); } fn main() { run(); }