QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159860#7105. Pixel Artucup-team296#AC ✓605ms22848kbC++145.0kb2023-09-02 18:56:512023-09-04 04:30:49

Judging History

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

  • [2023-09-04 04:30:49]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:605ms
  • 内存:22848kb
  • [2023-09-02 18:56:52]
  • 评测
  • 测评结果:100
  • 用时:676ms
  • 内存:22868kb
  • [2023-09-02 18:56:51]
  • 提交

answer

#include <bits/stdc++.h>

#define long long long int
#define DEBUG
using namespace std;

// @author: pashka

struct Dsu {

    vector<int> p;

    Dsu(int n) {
        p.resize(n);
        for (int i = 0; i < n; i++) p[i] = i;
    }

    int get(int x) {
        if (p[x] != x) p[x] = get(p[x]);
        return p[x];
    }

    bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) return false;
        p[x] = y;
        return true;
    }
};

struct test {
    void solve() {
        int n, m, k;
        cin >> n >> m >> k;
        vector<int> x1(k), x2(k), y1(k), y2(k);
        for (int i = 0; i < k; i++) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            x1[i]--, x2[i]--, y1[i]--, y2[i]--;
        }
        vector<long> res1(n + 1);
        {
            for (int i = 0; i < k; i++) {
                int d = y2[i] - y1[i] + 1;
                res1[x1[i]] += d;
                res1[x2[i] + 1] -= d;
            }
            for (int i = 1; i <= n; i++) {
                res1[i] += res1[i - 1];
            }
            for (int i = 1; i <= n; i++) {
                res1[i] += res1[i - 1];
            }
        }

        vector<long> res2(n + 1);
        for (int i = 0; i < k; i++) {
            res2[x1[i]]++;
        }

        {
            vector<int> yy;
            for (int i = 0; i < k; i++) {
                yy.push_back(y1[i]);
                yy.push_back(y1[i] - 1);
                yy.push_back(y1[i] + 1);
                yy.push_back(y2[i]);
                yy.push_back(y2[i] - 1);
                yy.push_back(y2[i] + 1);
            }
            sort(yy.begin(), yy.end());
            yy.erase(unique(yy.begin(), yy.end()), yy.end());
            m = yy.size();
            for (int i = 0; i < k; i++) {
                y1[i] = lower_bound(yy.begin(), yy.end(), y1[i]) - yy.begin();
                y2[i] = lower_bound(yy.begin(), yy.end(), y2[i]) - yy.begin();
            }
        }

        vector<vector<pair<int, int>>> e(n + 1);
        {
            vector<set<pair<int, int>>> xx(n);
            for (int i = 0; i < k; i++) {
                xx[x1[i]].insert({y1[i], i});
                xx[x1[i]].insert({y2[i], i});
                xx[x2[i]].insert({y1[i], i});
                xx[x2[i]].insert({y2[i], i});
            }
            for (int i = 0; i < k; i++) {
                if (x1[i] > 0) {
                    int yy = y1[i];
                    while (true) {
                        auto p = xx[x1[i] - 1].lower_bound({yy, 0});
                        if (p == xx[x1[i] - 1].end() || p->first > y2[i]) break;
                        e[x1[i]].push_back({i, p->second});
                        yy = p->first + 1;
                    }
                }
                if (x2[i] < n - 1) {
                    int yy = y1[i];
                    while (true) {
                        auto p = xx[x2[i] + 1].lower_bound({yy, 0});
                        if (p == xx[x2[i] + 1].end() || p->first > y2[i]) break;
                        e[x2[i] + 1].push_back({i, p->second});
                        yy = p->first + 1;
                    }
                }
            }
        }
        {
            vector<set<pair<int, int>>> yy(m);
            for (int i = 0; i < k; i++) {
                yy[y1[i]].insert({x1[i], i});
                yy[y2[i]].insert({x1[i], i});
                yy[y1[i]].insert({x2[i], i});
                yy[y2[i]].insert({x2[i], i});
            }
            for (int i = 0; i < k; i++) {
                if (y1[i] > 0) {
                    int xx = x1[i];
                    while (true) {
                        auto p = yy[y1[i] - 1].lower_bound({xx, 0});
                        if (p == yy[y1[i] - 1].end() || p->first > x2[i]) break;
                        e[p->first].push_back({i, p->second});
                        xx = p->first + 1;
                    }
                }
                if (y2[i] < m - 1) {
                    int xx = x1[i];
                    while (true) {
                        auto p = yy[y2[i] + 1].lower_bound({xx, 0});
                        if (p == yy[y2[i] + 1].end() || p->first > x2[i]) break;
                        e[p->first].push_back({i, p->second});
                        xx = p->first + 1;
                    }
                }
            }
        }

        Dsu dsu(k);

        for (int i = 0; i < n; i++) {
            for (auto [x, y]: e[i]) {
                if (dsu.unite(x, y)) {
                    res2[i]--;
                }
            }
        }

        for (int i = 1; i <= n; i++) {
            res2[i] += res2[i - 1];
        }

        for (int i = 0; i < n; i++) {
            cout << res1[i] << " " << res2[i] << "\n";
        }
    }
};

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        test().solve();
    }

    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3596kb

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: 0
Accepted
time: 605ms
memory: 22848kb

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:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed