#define CPP17 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef CPP17 #include #endif // Yay!! #define endl codeforces // macros for iterator #define ALL(v) std::begin(v), std::end(v) #define ALLR(v) std::rbegin(v), std::rend(v) // alias using ll = std::int64_t; using ull = std::uint64_t; using pii = std::pair; using tii = std::tuple; using pll = std::pair; using tll = std::tuple; template using vec = std::vector; template using vvec = vec>; // variadic min/max template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } // variadic chmin/chmax template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } // multi demension array template struct multi_dim_array { using type = std::array::type, Head>; }; template struct multi_dim_array { using type = std::array; }; template using mdarray = typename multi_dim_array::type; #ifdef CPP17 // fill container template void fill_seq(T &t, F f, Args... args) { if constexpr (std::is_invocable::value) { t = f(args...); } else { for (ssize_t i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); } } #endif // make multi dimension vector template vec make_v(ssize_t sz) { return vec(sz); } template auto make_v(ssize_t hs, Tail&&... ts) { auto v = std::move(make_v(std::forward(ts)...)); return vec(hs, v); } // init namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } int main() { using square = std::tuple; const ll inf = 5e15; ll n; std::cin >> n; vec sv(n); for (auto &&e : sv) { ll a, b, c, d; std::cin >> a >> b >> c >> d; e = square(a, b, c, d); } std::set st[4]; for (ll i = 0; i < 4; i++) { st[i].emplace(inf, 0); // x, y st[i].emplace(0, inf); } for (auto e : sv) { auto [ xa, ya, xb, yb ] = e; pll rngs[] = { pll(xb, yb), pll(-xa, yb), pll(-xa, -ya), pll(xb, -ya) }; ll ans = 0; for (ll i = 0; i < 4; i++) { auto [ x, y ] = rngs[i]; auto ite = st[i].lower_bound(pll(x, y)); if (y <= ite->second) continue; vec rp; bool update = false; while (true) { auto pite = std::prev(ite); ll lx = x - pite->first; ll ly = std::min(pite->second, y) - ite->second; ans += lx * ly; if (lx * ly) update = true; if (pite->second <= y) rp.push_back(*pite); if (y <= pite->second) break; ite = pite; } for (auto &&e : rp) st[i].erase(e); if (update) st[i].emplace(x, y); } std::cout << ans << "\n"; } return 0; }