QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#160374#7105. Pixel Artucup-team1191#AC ✓344ms11284kbC++205.9kb2023-09-02 20:18:042023-09-04 04:30:53

Judging History

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

  • [2023-09-04 04:30:53]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:344ms
  • 内存:11284kb
  • [2023-09-02 20:18:05]
  • 评测
  • 测评结果:100
  • 用时:345ms
  • 内存:11240kb
  • [2023-09-02 20:18:04]
  • 提交

answer

/*
    author:  Maksim1744
    created: 02.09.2023 14:45:16
*/

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T> &v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T> &v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T> &v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>  v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator--           (pair<T, U> &p){--p.first; --p.second;            return  p;}
template<typename T, typename U> pair<T,U>& operator++           (pair<T, U> &p){++p.first; ++p.second;            return  p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>  p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define SHOW_COLORS
#include "/mnt/c/Libs/tools/print.cpp"
#else
#define show(...) void(0)
#define debugf(fun)   fun
#define debugv(var)   var
#define mclock    void(0)
#define shows     void(0)
#define debug  if (false)
#define OSTREAM(...)    ;
#define OSTREAM0(...)   ;
#endif

struct Palka {
    int r1, r2;
    int c1, c2;
};

struct DSU {
    vector<int> rk;
    vector<int> p;
    int comps;
    int n;

    DSU(int n = 1) : n(n) {
        reset(n);
    }

    void reset(int n) {
        comps = n;
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        rk.assign(n, 1);
    }

    int par(int v) {
        return v == p[v] ? v : p[v] = par(p[v]);
    }

    bool un(int u, int v) {
        u = par(u);
        v = par(v);
        if (u == v) return false;
        if (rk[u] > rk[v]) swap(u, v);
        p[u] = v;
        rk[v] += rk[u];
        --comps;
        return true;
    }

    bool check(int u, int v) {
        return par(u) == par(v);
    }
};

void test_case(int test) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<Palka> palki(k);
    for (int i = 0; i < k; ++i) {
        auto& p = palki[i];
        cin >> p.r1 >> p.c1 >> p.r2 >> p.c2;
        --p.r1; --p.c1; --p.r2; --p.c2;
    }
    sort(palki.begin(), palki.end(), [](const auto& a, const auto& b) {
        return a.r1 < b.r1;
    });
    DSU d(k);
    set<pair<pair<int, int>, int>> st;
    vector<int> ans_comps;
    int ind = 0;
    vector<vector<pair<pair<int, int>, int>>> dl(n + 1);
    for (int i = 0; i < n; ++i) {
        shows;
        show(i);
        vector<pair<pair<int, int>, int>> todo;
        while (ind < k && palki[ind].r1 == i) {
            const auto& p = palki[ind];
            auto it = st.lower_bound({mp(p.c1, -1), -1});
            if (it != st.begin() && prev(it)->first.second >= p.c1) --it;
            while (it != st.end()) {
                if (it->first.first > p.c2) break;
                d.un(ind, it->second);
                ++it;
            }
            todo.eb(mp(p.c1, p.c2), ind);
            dl[p.r2 + 1].eb(mp(p.c1, p.c2), ind);

            ++ind;
        }
        show(st, d.comps);

        for (auto s : dl[i])
            st.erase(s);
        show(st, d.comps);

        for (auto pr : todo) {
            const auto& p = palki[pr.second];
            auto it = st.lower_bound({mp(p.c1, -1), -1});
            if (it != st.end() && it->first.first == p.c2 + 1)
                d.un(it->second, pr.second);
            if (it != st.begin() && prev(it)->first.second == p.c1 - 1)
                d.un(prev(it)->second, pr.second);
        }
        show(st, d.comps);

        sort(todo.begin(), todo.end(), [&](auto a, auto b) {
            return a.first.first < b.first.first;
        });

        for (int i = 0; i + 1 < todo.size(); ++i)
            if (todo[i].first.second + 1 == todo[i + 1].first.first)
                d.un(todo[i].second, todo[i + 1].second);
        show(st, d.comps);
        for (auto p : todo)
            st.insert(p);
        show(st, d.comps);
        ans_comps.pb(d.comps - (k - ind));
    }

    vector<ll> sz(n + 1);
    for (auto p : palki) {
        if (p.r1 == p.r2) continue;
        sz[p.r1]++;
        sz[p.r2 + 1]--;
    }
    for (int i = 1; i < sz.size(); ++i)
        sz[i] += sz[i - 1];
    for (auto p : palki) {
        if (p.r1 != p.r2) continue;
        sz[p.r1] += p.c2 - p.c1 + 1;
    }
    for (int i = 1; i < sz.size(); ++i)
        sz[i] += sz[i - 1];

    for (int i = 0; i < n; ++i) {
        cout << sz[i] << ' ' << ans_comps[i] << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

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

    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 344ms
memory: 11284kb

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