#include using namespace std; #include #include #include #include #include #include #include #include #if defined(__unix__) || defined(__APPLE__) #include #endif template std::istream& operator>>(std::istream& is, std::vector& v); template std::istream& operator>>(std::istream& is, std::pair& p); template std::istream& operator>>(std::istream& is, std::tuple& t); namespace input_detail { #ifdef LOCAL inline std::size_t& read_count() { static std::size_t count = 0; return count; } inline bool& failed_read() { static bool failed = false; return failed; } inline bool stdin_is_terminal() { #if defined(__unix__) || defined(__APPLE__) return isatty(fileno(stdin)); #else return false; #endif } struct EndOfInputChecker { ~EndOfInputChecker() { if (stdin_is_terminal() || failed_read() || std::cin.bad()) return; std::cin >> std::ws; std::string token; if (std::cin >> token) { std::cerr << "[input error] 入力が余っています。\n" << " 最初に余った値: " << token << '\n' << " N と M、H と W、辺数 m、配列長 n などを間違えていないか確認してください。\n"; std::abort(); } } }; inline void ensure_end_checker() { static EndOfInputChecker checker; (void)checker; } inline void begin_input() { ensure_end_checker(); } template void read_one(std::istream& is, T& value) { if (&is != &std::cin) { is >> value; return; } ensure_end_checker(); ++read_count(); if (!(is >> value)) { failed_read() = true; std::cerr << "[input error] 入力が足りないか、型が合いません。\n" << " " << read_count() << " 個目の値を読み込めませんでした。\n" << " N と M、H と W、辺数 m、配列長 n などを間違えていないか確認してください。\n"; std::abort(); } } #else inline void begin_input() { } template void read_one(std::istream& is, T& value) { is >> value; } #endif template void read_values(Args&... args) { (read_one(std::cin, args), ...); } } struct FastIO { FastIO() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); } }; inline FastIO fast_io_init; template std::istream& operator>>(std::istream& is, std::pair& p) { input_detail::read_one(is, p.first); input_detail::read_one(is, p.second); return is; } template void read_tuple_impl(std::istream& is, Tuple& t, std::index_sequence) { (..., input_detail::read_one(is, std::get(t))); } template std::istream& operator>>(std::istream& is, std::tuple& t) { read_tuple_impl(is, t, std::index_sequence_for{}); return is; } template std::istream& operator>>(std::istream& is, std::vector& v) { for (auto& elem : v) { input_detail::read_one(is, elem); } return is; } template struct is_pair : std::false_type {}; template struct is_pair> : std::true_type {}; template struct is_tuple : std::false_type {}; template struct is_tuple> : std::true_type {}; template struct is_vector : std::false_type {}; template struct is_vector> : std::true_type {}; template void adjust_zero_indexed(T& val) { using DecayedT = std::decay_t; if constexpr (is_pair::value) { adjust_zero_indexed(val.first); adjust_zero_indexed(val.second); } else if constexpr (is_tuple::value) { std::apply([](auto&... args) { (adjust_zero_indexed(args), ...); }, val); } else if constexpr (is_vector::value) { for (auto& elem : val) { adjust_zero_indexed(elem); } } else if constexpr (std::is_arithmetic_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && !std::is_same_v && #if defined(__cpp_char8_t) !std::is_same_v && #endif !std::is_same_v && !std::is_same_v && !std::is_same_v) { --val; } else { } } using default_type = long; template void read(Args&... args) { input_detail::read_values(args...); } template T read_val() { T val; input_detail::read_one(std::cin, val); return val; } template std::pair read_pair() { std::pair p; input_detail::begin_input(); std::cin >> p; return p; } template std::tuple read_tuple() { std::tuple t; input_detail::begin_input(); std::cin >> t; return t; } template && !std::is_same_v, int> = 0> std::vector read_vec(Size n, bool zero_indexed = false) { std::vector v(n); input_detail::begin_input(); std::cin >> v; if (zero_indexed) { adjust_zero_indexed(v); } return v; } template std::vector read_vec(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec(n, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_pair(Size n, bool zero_indexed = false) { return read_vec>(n, zero_indexed); } template std::vector> read_vec_pair(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_pair(n, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_tuple(Size n, bool zero_indexed = false) { return read_vec>(n, zero_indexed); } template std::vector> read_vec_tuple(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_tuple(n, zero_indexed); } template std::vector> read_vec_grid(int h, int w, bool zero_indexed = false) { std::vector> grid(h, std::vector(w)); input_detail::begin_input(); std::cin >> grid; if (zero_indexed) { adjust_zero_indexed(grid); } return grid; } template std::vector> read_vec_grid(bool zero_indexed = false) { int h, w; input_detail::read_values(h, w); return read_vec_grid(h, w, zero_indexed); } template && !std::is_same_v, int> = 0> std::vector> read_vec_var(Size n, bool zero_indexed = false) { std::vector> res(n); input_detail::begin_input(); for (int i = 0; i < static_cast(n); ++i) { int m; input_detail::read_one(std::cin, m); res[i] = read_vec(m, zero_indexed); } return res; } template std::vector> read_vec_var(bool zero_indexed = false) { int n; input_detail::read_one(std::cin, n); return read_vec_var(n, zero_indexed); } template T read_zero_idx() { T val; input_detail::read_one(std::cin, val); adjust_zero_indexed(val); return val; } inline std::vector> read_graph(int n, int m, bool directed = false) { std::vector> g(n); input_detail::begin_input(); for (int i = 0; i < m; ++i) { int u = read_zero_idx(); int v = read_zero_idx(); g[u].push_back(v); if (!directed) { g[v].push_back(u); } } return g; } inline std::vector> read_graph(bool directed = false) { int n, m; input_detail::read_values(n, m); return read_graph(n, m, directed); } template struct Edge { int to; Cost cost; Edge() = default; Edge(int to, Cost cost) : to(to), cost(cost) {} }; template inline std::vector>> read_weighted_graph(int n, int m, bool directed = false) { std::vector>> g(n); input_detail::begin_input(); for (int i = 0; i < m; ++i) { int u = read_zero_idx(); int v = read_zero_idx(); Cost w; input_detail::read_one(std::cin, w); g[u].push_back(Edge{v, w}); if (!directed) { g[v].push_back(Edge{u, w}); } } return g; } template inline std::vector>> read_weighted_graph(bool directed = false) { int n, m; input_detail::read_values(n, m); return read_weighted_graph(n, m, directed); } #include #include #include #include #define ALL(a) (a).begin(), (a).end() using i128 = __int128; template inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; } template inline T div_ceil(T a, T b) { if (a > 0) return a / b + (a % b != 0); return a / b; } template inline T div_floor(T a, T b) { if (a < 0) return a / b - (a % b != 0); return a / b; } template inline T mod(T a, T m) { a %= m; if (a < 0) a += m; return a; } template inline constexpr T INF = std::numeric_limits::max() / 2; template <> inline constexpr float INF = std::numeric_limits::infinity(); template <> inline constexpr double INF = std::numeric_limits::infinity(); template <> inline constexpr long double INF = std::numeric_limits::infinity(); template auto make_vector(size_t size, T&& initial_value) { return std::vector>(size, std::forward(initial_value)); } template auto make_vector(size_t size, Args&&... args) { auto inner = make_vector(std::forward(args)...); return std::vector(size, inner); } template inline std::vector iota_vec(int n, T start = 0) { std::vector v(n); std::iota(v.begin(), v.end(), start); return v; } template inline std::vector doubled_vec(const std::vector& v) { std::vector res; res.reserve(v.size() * 2); res.insert(res.end(), v.begin(), v.end()); res.insert(res.end(), v.begin(), v.end()); return res; } inline void Yes(bool b = true) { std::println("{}", (b ? "Yes" : "No")); } inline void No() { std::println("No"); } #ifdef LOCAL #include #else #define debug(...) #endif #include #include template struct Imos2D { int h, w; std::vector> data; Imos2D(int h, int w) : h(h), w(w), data(h + 2, std::vector(w + 2, 0)) {} void add(int y1, int x1, int y2, int x2, T val = T(1)) { y1 = std::clamp(y1, 0, h); x1 = std::clamp(x1, 0, w); y2 = std::clamp(y2, 0, h); x2 = std::clamp(x2, 0, w); if (y1 >= y2 || x1 >= x2) return; data[y1][x1] += val; data[y1][x2] -= val; data[y2][x1] -= val; data[y2][x2] += val; } void add_inclusive(int u, int d, int l, int r, T val = T(1)) { if (h <= 0 || w <= 0) return; u = std::clamp(u, 0, h - 1); d = std::clamp(d, 0, h - 1); l = std::clamp(l, 0, w - 1); r = std::clamp(r, 0, w - 1); if (u > d || l > r) return; add(u, l, d + 1, r + 1, val); } void add_rect_udlr(int u, int d, int l, int r, T val = T(1)) { add_inclusive(u, d, l, r, val); } void add_rect(int u, int d, int l, int r, T val = T(1)) { add_rect_udlr(u, d, l, r, val); } void build() { for (int y = 0; y <= h; ++y) { for (int x = 1; x <= w; ++x) { data[y][x] += data[y][x - 1]; } } for (int x = 0; x <= w; ++x) { for (int y = 1; y <= h; ++y) { data[y][x] += data[y - 1][x]; } } } T get(int y, int x) const { if (y < 0 || y >= h || x < 0 || x >= w) return T(0); return data[y][x]; } }; template struct PrefixSum2D { int h, w; std::vector> pre; PrefixSum2D(int h, int w) : h(h), w(w), pre(h + 1, std::vector(w + 1, 0)) {} void set(int y, int x, T val) { if (y >= 0 && y < h && x >= 0 && x < w) { pre[y + 1][x + 1] = val; } } void build() { for (int i = 0; i <= h; ++i) { for (int j = 0; j < w; ++j) { pre[i][j + 1] += pre[i][j]; } } for (int j = 0; j <= w; ++j) { for (int i = 0; i < h; ++i) { pre[i + 1][j] += pre[i][j]; } } } T sum_half(int y1, int x1, int y2, int x2) const { y1 = std::clamp(y1, 0, h); x1 = std::clamp(x1, 0, w); y2 = std::clamp(y2, 0, h); x2 = std::clamp(x2, 0, w); if (y1 >= y2 || x1 >= x2) return T(0); return pre[y2][x2] - pre[y1][x2] - pre[y2][x1] + pre[y1][x1]; } T sum(int u, int d, int l, int r) const { if (h <= 0 || w <= 0) return T(0); u = std::clamp(u, 0, h - 1); d = std::clamp(d, 0, h - 1); l = std::clamp(l, 0, w - 1); r = std::clamp(r, 0, w - 1); if (u > d || l > r) return T(0); return sum_half(u, l, d + 1, r + 1); } }; void solve() { ios::sync_with_stdio(false); cin.tie(nullptr); int H, W, N; read(H, W, N); Imos2D imos(H, W); for (int i = 0; i < N; i++) { int r1, c1, r2, c2; read(r1, c1, r2, c2); r1--, c1--; imos.add(r1, c1, r2, c2, 1); } imos.build(); int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans += (imos.get(i, j) == 0); } } println("{}", ans); } int main() { solve(); }