QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#113303#6561. Fail FastrniyaWA 1ms3708kbC++173.4kb2023-06-16 22:56:052023-06-16 22:56:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 22:56:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3708kb
  • [2023-06-16 22:56:05]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif


template <class S, S (*op)(S, S)> struct ForestScheduling {
    S tot;
    std::vector<int> ord;

    ForestScheduling(const std::vector<int>& par, std::vector<S> x) : tot() {
        int n = par.size();
        assert(int(x.size()) == n);
        dsu.assign(n + 1, -1);
        std::priority_queue<T> pq;
        std::vector<int> tails(n + 1), nxt(n + 1, -1);
        for (int i = 0; i < n; i++) {
            tails[i] = i;
            pq.push({x[i], i, i});
        }
        tails[n] = n;
        while (not pq.empty()) {
            auto [tmp, v, tail] = pq.top();
            pq.pop();
            if (tails[v] == tail) {
                int u = leader(par[v] >= 0 ? par[v] : n);
                merge(u, v);
                nxt[tails[u]] = v;
                tails[u] = tail;
                if (u == n)
                    tot = op(tot, x[v]);
                else {
                    x[u] = op(x[u], x[v]);
                    pq.push({x[u], u, tail});
                }
            }
        }
        for (int i = 0, cur = n; i < n; i++) {
            cur = nxt[cur];
            ord.emplace_back(cur);
        }
    }

    int operator[](int i) const { return ord[i]; }

  private:
    struct T {
        S s;
        int head, tail;
        bool operator<(const T& rhs) const { return rhs.s < s; }
    };
    std::vector<int> dsu;

    int leader(int u) { return dsu[u] < 0 ? u : (dsu[u] = leader(dsu[u])); }

    bool merge(int u, int v) {
        u = leader(u), v = leader(v);
        if (u == v) return false;
        dsu[u] += dsu[v];
        dsu[v] = u;
        return true;
    }
};

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

struct S {
    ll CPU;
    double p;
    S() : CPU(0), p(1) {}
    S(ll CPU, double p) : CPU(CPU), p(p) {}
    bool operator<(const S& rhs) const { return CPU * (1 - rhs.p) < rhs.CPU * (1 - p); }
};

S op(S l, S r) { return S(l.CPU + r.CPU, l.p * r.p); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> par(n);
    vector<S> test;
    for (int i = 0; i < n; i++) {
        int c;
        double p;
        cin >> c >> p >> par[i];
        par[i]--;
        test.emplace_back(c, p);
    }

    ForestScheduling<S, op> G(par, test);
    for (int i = 0; i < n; i++) cout << G[i] + 1 << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
100 0.5 0
200 0.1 1
10 0.5 2
10 0.9 0

output:

4
1
2
3

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3656kb

input:

4
84 0.716 0
91 0.115 0
19 0.640 1
103 0.455 0

output:

2
4
1
3

result:

wrong answer your plan is not optimal