QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163571#7105. Pixel ArtjrjyyWA 330ms13136kbC++202.3kb2023-09-04 11:10:042023-09-04 11:10:05

Judging History

你现在查看的是最新测评结果

  • [2023-09-04 11:10:05]
  • 评测
  • 测评结果:WA
  • 用时:330ms
  • 内存:13136kb
  • [2023-09-04 11:10:04]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

struct DSU {
    std::vector<int> fa, sz;
    DSU(int n = 0) { init(n); }
    void init(int n) {
        fa.resize(n), std::iota(fa.begin(), fa.end(), 0);
        sz.assign(n, 1);
    }
    int find(int x) {
        while (x != fa[x]) x = fa[x] = fa[fa[x]];
        return x;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    bool merge(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return false;
        return sz[x] += sz[y], fa[y] = x, true;
    }
    int size(int x) { return sz[find(x)]; }
};

void solve() {
    int n, m, k;
    std::cin >> n >> m >> k;

    std::vector<std::vector<std::array<int, 3>>> add(n + 1), del(n + 1);
    for (int i = 0; i < k; ++i) {
        int r1, c1, r2, c2;
        std::cin >> r1 >> c1 >> r2 >> c2;
        --r1, --c1;
        add[r1].push_back({c1, c2, i});
        del[r2].push_back({c1, c2, i});
    }

    i64 ans = 0;
    int width = 0, comp = 0;
    DSU dsu(k);
    auto merge = [&](int x, int y) {
        comp -= dsu.merge(x, y);
    };

    std::map<int, std::pair<int, int>> mp;
    for (int i = 0; i < n; ++i) {
        for (auto [l, r, id] : add[i]) {
            auto it = mp.lower_bound(l);
            if (it != mp.begin()) {
                --it;
            }
            while (it != mp.end() && it->first < r) {
                if (l < it->second.first) {
                    merge(id, it->second.second);
                }
                ++it;
            }
            width += r - l;
            comp += 1;
        }
        for (auto [l, r, id] : del[i]) {
            mp.erase(l);
            width -= r - l;
        }
        for (auto [l, r, id] : add[i]) {
            auto it = mp.insert({l, std::pair{r, id}}).first;
            if (it != mp.begin() && std::prev(it)->second.first == l) {
                merge(id, std::prev(it)->second.second);
            }
            if (it != mp.end() && std::next(it)->first == r) {
                merge(id, std::next(it)->second.second);
            }
        }
        ans += width;

        std::cout << ans << ' ' << comp << '\n';
    }
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3424kb

input:

3
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 330ms
memory: 13136kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

wrong answer 115th lines differ - expected: '10 10', found: '10 9'