#![allow(non_snake_case, unused_imports)] use std::cmp::{min, max}; use std::collections::{BinaryHeap, Bound, HashMap, HashSet, VecDeque}; use std::hash::Hash; use std::ops::RangeBounds; use ac_library::{Additive, Min, Segtree}; use proconio::{input, marker::Usize1, marker::Chars}; use itertools::Itertools; #[allow(unused_macros)] macro_rules! d { ( $( $x:expr ),* $(,)? ) => { eprintln!( concat!( $( stringify!($x), "={:?} " ),* ), $( $x ),* ); }; } #[allow(dead_code)] fn yn(b: bool) -> &'static str { if b { "Yes" } else { "No" } } fn imos2d(h: usize, w: usize, rects: &[(usize, usize, usize, usize, i64)]) -> Vec> { let mut imos = vec![vec![0; w+1]; h+1]; for &(r1, c1, r2, c2, v) in rects { imos[r1][c1] += v; imos[r1][c2 + 1] -= v; imos[r2+1][c1] -= v; imos[r2+1][c2 + 1] += v; } for r in 0..h { for c in 1..w { imos[r][c] += imos[r][c-1]; } } for r in 1..h { for c in 0..w { imos[r][c] += imos[r-1][c]; } } imos.truncate(h); for row in &mut imos { row.truncate(w); } imos } fn main() { input! { H: usize, W: usize, N: usize, LRS: [(Usize1, Usize1, Usize1, Usize1); N], } let lrs = LRS.iter() .map(|&(r1, c1, r2, c2)| (r1, c1, r2, c2, 1)) .collect_vec(); let g = imos2d(H, W, &lrs); let mut ans = 0; for i in 0..H { for j in 0..W { if g[i][j] == 0 { ans += 1; } } } println!("{}", ans); }