提出 #74129584


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

int main() {
    int H, W, h, w, N;
    cin >> H >> W >> h >> w >> N;
    
    vector<int> blockT(N), blockB(N), blockL(N), blockR(N);

    vector<pair<pair<int, int>, int>> actI;
    vector<int> actPoints;
    for (int i = 0; i < N; ++i) {
        int r, c; cin >> r >> c;
        blockT[i] = r-h+1, blockB[i] = r; // not doing max(..., 1)
        blockL[i] = max(c-w+1, 1), blockR[i] = c;
        actI.push_back({{blockL[i], +1}, i});
        actI.push_back({{blockR[i]+1, -1}, i});
        actPoints.push_back(blockL[i]);
        actPoints.push_back(blockR[i]+1);
    }
    sort(actI.begin(), actI.end());
    sort(actPoints.begin(), actPoints.end());
    actPoints.resize(unique(actPoints.begin(), actPoints.end()) - actPoints.begin());

    int lastRow = H - h + 1, lastCol = W - w + 1;

    long long blockedArea = 0;
    map<int, int> segmentStart;
    int blockedRows = 0, sectionStart = 1;
    int nextAct = 0;

    auto findRange = [&](int b) {
        int from = blockT[b], to = blockB[b];
        auto it = segmentStart.lower_bound(blockT[b]);
        if (it != segmentStart.begin()) {
            auto it2 = prev(it);
            from = max(from, it2->first+h);
        }
        if (it != segmentStart.end()) {
            to = min(to, it->first-1);
        }
        return pair<int, int>{from, to};
    };
    auto changeSeg = [&](int from, int to, int sign) {
        from = max(from, 1);
        to = min(to, lastRow);
        if (from <= to) blockedRows += (to-from+1)*sign;
    };

    for (int c : actPoints) {
        if (c > lastCol) break;
        blockedArea += (long long)blockedRows * (c - sectionStart);
        sectionStart = c;

        while (nextAct < (int)actI.size() && actI[nextAct].first.first == c) {
            auto [pr, b] = actI[nextAct];
            int action = pr.second;

            if (action == -1) { // remove segment
                segmentStart[blockT[b]]--;
                if (segmentStart[blockT[b]] == 0) segmentStart.erase(blockT[b]);
                auto [from, to] = findRange(b);
                changeSeg(from, to, -1);
            } else { // add segment
                auto [from, to] = findRange(b);
                changeSeg(from, to, +1);
                segmentStart[blockT[b]]++;
            }

            ++nextAct;
        }
    }

    blockedArea += (long long)blockedRows * (lastCol+1 - sectionStart);

    cout << (long long)lastRow*lastCol - blockedArea << endl;
    return 0;
}

提出情報

提出日時
問題 F - Grid Clipping
ユーザ erekle
言語 C++ IOI-Style(GNU++20) (GCC 14.2.0)
得点 500
コード長 2581 Byte
結果 AC
実行時間 192 ms
メモリ 20468 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 4
AC × 28
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 0 ms 1640 KiB
00_sample_01.txt AC 0 ms 1640 KiB
00_sample_02.txt AC 0 ms 1640 KiB
00_sample_03.txt AC 0 ms 1640 KiB
01_handmade_00.txt AC 192 ms 13044 KiB
01_handmade_01.txt AC 119 ms 13044 KiB
01_handmade_02.txt AC 0 ms 1640 KiB
01_handmade_03.txt AC 0 ms 1640 KiB
01_handmade_04.txt AC 0 ms 1640 KiB
02_random_00.txt AC 130 ms 13040 KiB
02_random_01.txt AC 179 ms 20468 KiB
02_random_02.txt AC 129 ms 13044 KiB
02_random_03.txt AC 181 ms 20468 KiB
02_random_04.txt AC 180 ms 13044 KiB
02_random_05.txt AC 183 ms 13044 KiB
02_random_06.txt AC 179 ms 13044 KiB
02_random_07.txt AC 179 ms 13044 KiB
02_random_08.txt AC 180 ms 13044 KiB
02_random_09.txt AC 183 ms 13044 KiB
02_random_10.txt AC 178 ms 13144 KiB
02_random_11.txt AC 177 ms 13044 KiB
02_random_12.txt AC 182 ms 13044 KiB
02_random_13.txt AC 189 ms 13040 KiB
02_random_14.txt AC 160 ms 13044 KiB
02_random_15.txt AC 162 ms 13044 KiB
02_random_16.txt AC 158 ms 13040 KiB
02_random_17.txt AC 159 ms 13044 KiB
02_random_18.txt AC 160 ms 13044 KiB