結果

問題 No.1074 増殖
ユーザー finefine
提出日時 2020-06-05 22:46:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,530 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 174,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 16:38:41
合計ジャッジ時間 3,330 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 42 ms
4,380 KB
testcase_07 AC 43 ms
4,380 KB
testcase_08 AC 43 ms
4,380 KB
testcase_09 AC 61 ms
4,380 KB
testcase_10 AC 46 ms
4,380 KB
testcase_11 AC 49 ms
4,380 KB
testcase_12 AC 48 ms
4,380 KB
testcase_13 AC 117 ms
4,376 KB
testcase_14 AC 119 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

ll solve(ll x, ll y, map<ll, ll>& d) {
    auto itr = d.upper_bound(x);

    ll ng = 0, ok = 1e9;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        (d.lower_bound(mid)->second <= y ? ok : ng) = mid; 
    }

    ll diff = 0;
    auto itl = d.lower_bound(ok);
    if (ok <= x) {
        for (auto it = itl; ; ++it) {
            diff -= it->second * (it->first - prev(it)->first);
            if (it == itr) break;
        }
    }

    {
        auto pit = prev(itl);
        if (pit->second > y && y > itr->second && pit->first < x && x < itr->first) {
            diff += y * (x - pit->first);
            diff += itr->second * (itr->first - x);

            d.erase(itl, itr);
            d[x] = y;
        } else {
            return 0;
        }
    }

    assert(diff >= 0);
    return diff;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    map<ll, ll> d1, d2, d3, d4;
    d1[0] = 1e9;
    d1[1e9] = 0;
    d2[0] = 1e9;
    d2[1e9] = 0;
    d3[0] = 1e9;
    d3[1e9] = 0;
    d4[0] = 1e9;
    d4[1e9] = 0;

    for (int i = 0; i < n; i++) {
        ll xa, ya, xb, yb;
        cin >> xa >> ya >> xb >> yb;

        xa = abs(xa);
        ya = abs(ya);

        ll ans = 0;
        ans += solve(xa, ya, d1);
        ans += solve(xb, ya, d2);
        ans += solve(xa, yb, d3);
        ans += solve(xb, yb, d4);
        cout << ans << newl;
    }

    return 0;
}
0