QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278877#7617. Spectacleucup-team859WA 47ms10972kbC++173.3kb2023-12-07 21:48:132023-12-07 21:48:13

Judging History

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

  • [2023-12-07 21:48:13]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:10972kb
  • [2023-12-07 21:48:13]
  • 提交

answer

#include <bits/stdc++.h>

#define lsb(x) (x & (-x))

using ull = unsigned long long;
using ll = long long;

using namespace std;


#ifdef HOME
    #define LOCAL_CHECK(x) assert(x);
#else
    #define LOCAL_CHECK(x)
#endif 

// https://judge.yosupo.jp/submission/159946

template<bool _CompressPath = true>
class DSU {
public:
    DSU(int n) : n(n) {
        LOCAL_CHECK(n > 0);

        link.resize(n, -1);
        size.resize(n, 1);
    }

    int getRoot(int x) noexcept {
        LOCAL_CHECK(0 <= x && x < n);

        if (_CompressPath) {
            return link[x] == -1 ? x : link[x] = getRoot(link[x]);
        } else {
            return link[x] == -1 ? x : getRoot(link[x]);
        }
    }

    bool join(int x, int y) noexcept(_CompressPath) {
        LOCAL_CHECK(0 <= x && x < n);
        LOCAL_CHECK(0 <= y && y < n);

        x = getRoot(x), y = getRoot(y);
        if (size[x] > size[y]) {
            std::swap(x, y);
        }

        bool joined = (x != y);
        if (joined) {
            link[x] = y;
            size[y] += size[x];
            if (!_CompressPath) {
                joinedLinks.push(x);
            }
        } else {
            if (!_CompressPath) {
                joinedLinks.push(-1);
            }
        }

        return joined;
    }

    inline int getSize(int x) noexcept {
        return size[getRoot(x)];
    }

    void undo() {
        static_assert(!_CompressPath);

        if (!joinedLinks.empty()) {
            auto lastJoin = joinedLinks.top();

            joinedLinks.pop();

            if (lastJoin == -1) return;

            size[link[lastJoin]] -= size[lastJoin];
            link[lastJoin] = -1;
        } else {
            assert(false);
        }
    }

private:
    std::vector<int> link;
    std::vector<int> size;
    int n;

    std::stack<int> joinedLinks;
};

int main() {
#ifdef HOME
    ifstream cin("input.in");
    ofstream cout("output.out");
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;

    vector<ll> r(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> r[i];
    }
    sort(r.begin() + 1, r.end());

    vector<pair<ll, int>> diffs;
    for (int i = 1; i < n; i++) {
        diffs.push_back({r[i + 1] - r[i], i});
    }

    sort(diffs.begin(), diffs.end());
    DSU<true> dsu(n + 1);

    constexpr ll INF = 1e18;
    vector<ll> results(n + 2, INF);
    int current = 0;
    int i = 0;

    while (i < (int)diffs.size()) {
        int j = i;
        while (j < (int)diffs.size() && diffs[i].first == diffs[j].first) {
            int pos = diffs[i].second;
            if  (dsu.getRoot(pos) != dsu.getRoot(pos + 1)) {
                current -= dsu.getSize(pos) / 2;
                current -= dsu.getSize(pos + 1) / 2;
                dsu.join(pos, pos + 1);
                current += dsu.getSize(pos) / 2;
            }
            j++;
        }
        results[current] = min(results[current], diffs[i].first);        
        i = j;
    }

    for (int i = n / 2; i >= 1; i--) {
        results[i] = min(results[i], results[i + 1]);
    }
    for (int i = 1; i <= n / 2; i++) {
        cout << results[i] << " ";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
100 13 20 14 10 105

output:

1 5 6 

result:

ok single line: '1 5 6 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

2
1 1000000000000000000

output:

999999999999999999 

result:

ok single line: '999999999999999999 '

Test #3:

score: -100
Wrong Answer
time: 47ms
memory: 10972kb

input:

200000
30977570544127554 30977570529630987 30977570554040634 30977570903666181 30977570284338326 30977570675313216 30977569987827221 30977570780807305 30977570623822067 30977570207823010 30977569932624714 30977570440962037 30977570343703869 30977570239637322 30977570141845422 30977570372368100 30977...

output:

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 68 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 ...

result:

wrong answer 1st lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...99 9999 10000 10000 10000 10000', found: '0 1 2 3 4 5 6 7 8 9 10 11 12 1...0000000000 1000000000000000000 '