QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159756#7105. Pixel Artucup-team296#WA 519ms20636kbC++145.0kb2023-09-02 18:33:502023-09-02 18:33:50

Judging History

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

  • [2023-09-02 18:33:50]
  • 评测
  • 测评结果:WA
  • 用时:519ms
  • 内存:20636kb
  • [2023-09-02 18:33:50]
  • 提交

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].find({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].find({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++) {
                if (x1[i] == x2[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].find({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].find({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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 519ms
memory: 20636kb

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 51
50 50
150 100
200 100
2 1
4 1
6 2
8 3
10 4
12 5
14 6
16 7
18 8
20 9
22 10
24 11
26 12
28 13
30 14
32 15
34 16
36 17
38 18
40 19
42 20
44 21
46 22
48 23
50 24
52 25
54 26
56 27
58 28
60 29
62 30
64 31
66 32
68 33
70 34
72 35
74 36
76 37
78 38
80 39
82 4...

result:

wrong answer 10th lines differ - expected: '200 1', found: '200 51'