#include // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Fri Jun 5 22:30:45 JST 2020 **/ const Int INF = 1e9; struct Plane { std::map mp; Int dif = 0; Plane() { mp[0] = INF; mp[INF] = 0; } void erase(Int x) { auto it = mp.lower_bound(x); assert(it->first == x); Int lm = std::next(it)->second; Int dx = x - std::prev(it)->first; dif -= dx * (it->second - lm); mp.erase(it); } Int add(Int x, Int y) { dif = 0; { auto it = mp.lower_bound(x); if (it->second >= y) return dif; } while (1) { auto it = std::prev(mp.upper_bound(x)); if (it->second > y) break; erase(it->first); } { auto it = mp.upper_bound(x); Int lm = it->second; Int dx = x - std::prev(it)->first; dif += dx * (y - lm); } mp[x] = y; return dif; } }; signed main() { Int n; std::cin >> n; std::vector ps(4); REP(i, n) { Int xa, ya, xb, yb; std::cin >> xa >> ya >> xb >> yb; Int ans = 0; ans += ps[0].add(xb, yb); ans += ps[1].add(-xa, yb); ans += ps[2].add(xb, -ya); ans += ps[3].add(-xa, -ya); std::cout << ans << "\n"; } }