QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159722#7105. Pixel Artucup-team1600#AC ✓209ms11952kbC++205.0kb2023-09-02 18:26:582023-09-04 04:30:46

Judging History

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

  • [2023-09-04 04:30:46]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:209ms
  • 内存:11952kb
  • [2023-09-02 18:27:01]
  • 评测
  • 测评结果:100
  • 用时:230ms
  • 内存:11932kb
  • [2023-09-02 18:26:58]
  • 提交

answer

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef LOCAL
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
inline bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
inline bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifdef LOCAL
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif // LOCAL

const int max_n = -1, inf = 1000111222;


struct dsu {
public:
    int n;
    vector <int> p, cnt;

    inline void make_set (int v) {
        p[v] = v;
    }

    dsu (int n) : n(n) {
        p.resize(n);
        cnt.assign(n, 1);
        for (int i = 0; i < n; i++) {
            make_set(i);
        }
    }

    inline int get (int v) {
        if (p[v] == v) return v;
        return p[v] = get(p[v]); /// compressing path
    }

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


inline void test_case () {
    int n, m, k;
    cin >> n >> m >> k;
    vector <vector <pii> > h(n), add(n + 1);
    for (int i = 0, r0, c0, r1, c1; i < k; i++) {
        cin >> r0 >> c0 >> r1 >> c1;
        --r0, --r1, --c0, --c1;
        if (r0 == r1) {
            h[r1].pb({c0, c1});
        }
        else {
            add[r0].pb({c1, 1});
            add[r1 + 1].pb({c1, -1});
        }
    }
    ll cnt = 0;
    int cmp = 0, cur = 0, num = 0;
    vector <pair<pii, int> > last;
    vector <int> id(m, -1);
    dsu t(k);
    for (int i = 0; i < n; i++) {
        vector <pair<pii, int> > have;
        sort(all(add[i]));
        for (auto &j : add[i]) {
            cur += j.second;
            if (j.second == -1) {
                last.pb({{j.first, j.first}, id[j.first]});
                id[j.first] = -1;
            }
            else {
                id[j.first] = num++;
                have.pb({{j.first, j.first}, id[j.first]});
                ++cmp;
            }
        }
        for (auto &j : h[i]) {
            cnt += j.second - j.first + 1;
            ++cmp;
            have.pb({j, num++});
        }
        cnt += cur;
        sort(all(last));
        sort(all(have));
        int p = 0;
        pair<pii, int> prv{{-2, -2}, -2};
        for (auto &j : have) {
            while (p < len(last) && last[p].first.second < j.first.first) {
                ++p;
            }
            while (p < len(last) && last[p].first.second <= j.first.second) {
                if (t.unite(j.second, last[p].second)) {
                    --cmp;
                }
                ++p;
            }
            if (p < len(last) && last[p].first.first <= j.first.second) {
                if (t.unite(j.second, last[p].second)) {
                    --cmp;
                }
            }
            if (j.first.first && id[j.first.first - 1] != -1) {
                if (t.unite(j.second, id[j.first.first - 1])) {
                    --cmp;
                }
            }
            if (j.first.second + 1 < m && id[j.first.second + 1] != -1) {
                if (t.unite(j.second, id[j.first.second + 1])) {
                    --cmp;
                }
            }
            if (prv.first.second + 1 == j.first.first) {
                if (t.unite(j.second, prv.second)) {
                    --cmp;
                }
            }
            prv = j;
        }
        last.swap(have);
        cout << cnt << ' ' << cmp << '\n';
    }
}


int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    for (int test = 1; test <= t; test++) {
        test_case();
    }
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 209ms
memory: 11952kb

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