QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#240828#7105. Pixel Artpandapythoner#TL 0ms3620kbC++233.0kb2023-11-05 20:02:072023-11-05 20:02:07

Judging History

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

  • [2023-11-05 20:02:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3620kb
  • [2023-11-05 20:02:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

vector<int> dsu;

int get(int v) {
    return dsu[v] < 0 ? v : dsu[v] = get(dsu[v]);
}

bool unite(int a, int b) {
    a = get(a), b = get(b);
    if (a == b) return false;
    if (dsu[a] > dsu[b]) swap(a, b);
    dsu[a] += dsu[b];
    return dsu[b] = a, true;
}

struct seg {
    int l, r, idx;
    bool operator<(const seg& o) const {
        return r < o.r;
    }
    seg(int l, int r, int id) : l(l), r(r), idx(id) {}
};

struct rct {
    int r1, c1, r2, c2;
    rct(int r1 = 0, int c1 = 0, int r2 = 0, int c2 = 0) : r1(r1), c1(c1), r2(r2), c2(c2) {}
};

void solve() {
    int n, k, m;
    cin >> n >> m >> k;
    dsu.clear();
    map<int, vector<seg>> hor;
    map<int, vector<seg>> vert;
    vector<rct> r(k);
    for (int i = 0; i < k; ++i) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        r[i] = {r1, c1, r2, c2};
        if (r1 == r2) {
            hor[r1].emplace_back(c1, c2, i);
        } else {
            vert[c1].emplace_back(r1, r2, i);
        }
    }
    dsu.assign(k, -1);
    auto at = [&](int i, int j) {
        auto it = lower_bound(all(hor[i]), seg{j, j, -1});
        if (it != hor[i].end() && it->l <= j) {
            return it->idx;
        }
        it = lower_bound(all(vert[j]), seg{i, i, -1});
        if (it != vert[j].end() && it->l <= i) {
            return it->idx;
        }
        return -1;
    };
    vector<vector<pair<int, int>>> edges(n + 1);
    for (int i = 0; i < k; ++i) {
        for (auto [x, y] : {make_pair(r[i].r1, r[i].c1), make_pair(r[i].r2, r[i].c2)}) {
            for (auto [dx, dy] : {make_pair(-1, 0), make_pair(1, 0), make_pair(0, -1), make_pair(0, 1)}) {
                int j = at(x + dx, y + dy);
                if (j != i && j != -1) {
                    edges[max(x, x + dx)].emplace_back(i, j);
                }
            }
        }
    }
    vector<vector<int>> ev(n + 1);
    vector<int> cnt1(n + 1);
    vector<int> cnt2(n + 1);
    for (auto [r1, c1, r2, c2] : r) {
        if (r1 == r2) {
            ev[r1].emplace_back(c2 - c1 + 1);
        } else {
            cnt1[r1]++;
            cnt2[r2]++;
        }
    }

    int cntv = 0;
    ll cnt_b = 0, cnt_comp = 0;
    for (int i = 1; i <= n; ++i) {
        cntv += cnt1[i];
        cnt_b += cntv;
        cnt_comp += cnt1[i];
        for (int tp : ev[i]) {
            cnt_comp++;
            cnt_b += tp;
        }
        for (auto [a, b] : edges[i]) {
            cnt_comp -= unite(a, b);
        }
        cntv -= cnt2[i];
        cout << cnt_b << ' ' << cnt_comp << '\n';
    }
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
#ifdef LOCAL
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#endif
    int tt;
    cin >> tt;
    while (tt--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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: