結果

問題 No.1074 増殖
ユーザー knshnbknshnb
提出日時 2020-06-05 22:56:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,784 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 209,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 16:55:41
合計ジャッジ時間 3,568 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 26 ms
4,380 KB
testcase_07 AC 26 ms
4,380 KB
testcase_08 AC 27 ms
4,380 KB
testcase_09 AC 35 ms
4,376 KB
testcase_10 AC 19 ms
4,376 KB
testcase_11 AC 21 ms
4,376 KB
testcase_12 AC 20 ms
4,376 KB
testcase_13 AC 58 ms
4,380 KB
testcase_14 AC 59 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // 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<Int, Int> 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<Plane> 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";
    }
}
0