Submission #57528108


Source Code Expand

#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w, q;
    cin >> h >> w >> q;
    vector<set<int>> row(h), col(w);
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            row[i].insert(j);
            col[j].insert(i);
        }
    }

    auto erase = [&](int x, int y) {
        assert(x >= 0 && x < h && y >= 0 && y < w);
        assert(row[x].count(y) && col[y].count(x));
        row[x].erase(y);
        col[y].erase(x);
    };

    for(int i = 0; i < q; i++) {
        int r, c;
        cin >> r >> c;
        r--; c--;
        if(row[r].count(c)) {
            erase(r, c);
            continue;
        }
        auto r_it = row[r].lower_bound(c);
        if(r_it != row[r].end()) {
            assert(*r_it != c);
            erase(r, *r_it);
        }
        // Reload since previous pointer might have been invalidated.
        r_it = row[r].lower_bound(c);
        if(r_it != row[r].begin()) {
            assert(*prev(r_it) != c);
            erase(r, *prev(r_it));
        }
        auto c_it = col[c].lower_bound(r);
        if(c_it != col[c].end()) {
            assert(*c_it != r);
            erase(*c_it, c);
        }
        // Reload since previous pointer might have been invalidated.
        c_it = col[c].lower_bound(r);
        if(c_it != col[c].begin()) {
            assert(*prev(c_it) != r);
            erase(*prev(c_it), c);
        }
    }

    int ans = 0;
    for(auto x : row) {
        ans += x.size();
    }
    cout << ans << "\n";
    return 0;
}

Submission Info

Submission Time
Task D - Cross Explosion
User ExplodingFreeze
Language C++ 20 (gcc 12.2)
Score 400
Code Size 1717 Byte
Status AC
Exec Time 334 ms
Memory 59416 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 26
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_all_break_00.txt, 03_hack_00.txt, 03_hack_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3368 KiB
00_sample_01.txt AC 1 ms 3564 KiB
00_sample_02.txt AC 1 ms 3404 KiB
01_random_00.txt AC 280 ms 38748 KiB
01_random_01.txt AC 214 ms 38952 KiB
01_random_02.txt AC 269 ms 42524 KiB
01_random_03.txt AC 334 ms 42368 KiB
01_random_04.txt AC 309 ms 40512 KiB
01_random_05.txt AC 308 ms 42004 KiB
01_random_06.txt AC 321 ms 42024 KiB
01_random_07.txt AC 250 ms 42360 KiB
01_random_08.txt AC 230 ms 44308 KiB
01_random_09.txt AC 309 ms 40732 KiB
01_random_10.txt AC 252 ms 42604 KiB
01_random_11.txt AC 267 ms 41056 KiB
01_random_12.txt AC 280 ms 40808 KiB
01_random_13.txt AC 295 ms 41000 KiB
01_random_14.txt AC 295 ms 40528 KiB
01_random_15.txt AC 296 ms 40796 KiB
01_random_16.txt AC 264 ms 40600 KiB
01_random_17.txt AC 288 ms 43616 KiB
01_random_18.txt AC 326 ms 40668 KiB
01_random_19.txt AC 323 ms 40668 KiB
02_all_break_00.txt AC 174 ms 40916 KiB
03_hack_00.txt AC 170 ms 59220 KiB
03_hack_01.txt AC 180 ms 59416 KiB