답안 #880227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880227 2023-11-29T03:50:06 Z DylanSmith Harbingers (CEOI09_harbingers) Java 11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)

mt19937 rng;

struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    static const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    stack<pair<int, Line>> st;
    int getTime() { return sz(st); }
    void setTime(int t) {
        while (sz(st) > t) {
            auto p = st.top(); st.pop();
            if (p.first == 0) {
                insert(p.second);
            } else if (p.first == 1) {
                erase(p.second);
            } else {
                auto q = st.top(); st.pop();
                auto n = lower_bound(p.second);
                n->p = q.second.p;
            }
        }
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) return x->p = inf, 0;
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    bool isectR(iterator x, iterator y) {
        st.push({2, *x});
        bool res = isect(x, y);
        st.push({2, *x});
        return res;
    }
    void add(ll k, ll m) {
        st.push({1, {k, m, 0}});
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isectR(y, z)) st.push({0, *z}), z = erase(z);
        if (x != begin() && isectR(--x, y)) { st.push({0, *y}); isectR(x, y = erase(y)); }
        while ((y = x) != begin() && (--x)->p >= y->p)
            st.push({0, *y}), isectR(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};

vector<vector<int>> adj;
vector<ll> p;
LineContainer lc;
vector<ll> res;
vector<int> s, v;
void dfs(int u) {
    if (u > 0) {
        res[u] = -lc.query(v[u]) + s[u] + (ll)v[u] * p[u];
        lc.add(p[u], -res[u]);
    }
    for (int v : adj[u]) {
        int t = lc.getTime();
        dfs(v);
        lc.setTime(t);
    }
}

void solve() {
    int N; cin >> N;
    adj = vector<vector<int>>(N);
    vector<vector<int>> edges;
    for (int i = 0; i < N - 1; i++) {
        int u, v, k; cin >> u >> v >> k; u--; v--;
        edges.pb({u, v, k});
        adj[u].pb(v);
        adj[v].pb(u);
    }
    s = vector<int>(N);
    v = vector<int>(N);
    for (int i = 1; i < sz(s); i++) cin >> s[i] >> v[i];
    queue<int> q;
    q.push(0);
    vector<int> depth(N, 0);
    vector<int> srt;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        srt.pb(u);
        for (int v : adj[u]) {
            adj[v].erase(find(all(adj[v]), u));
            depth[v] = depth[u] + 1;
            q.push(v);
        }
    }
    p = vector<ll>(N, 0);
    for (auto &edge : edges) {
        int u = edge[0], v = edge[1], k = edge[2];
        if (depth[v] > depth[u]) swap(u, v);
        p[u] = k;
    }
    for (int u : srt) {
        for (int v : adj[u]) p[v] += p[u];
    }
    lc.add(0, 0);
    res = vector<ll>(N);
    dfs(0);
    for (int i = 1; i < sz(res); i++) {
        cout << res[i] << (i == sz(res) - 1 ? "\n" : " ");
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    solve();

    return 0;
}

Compilation message

harbingers.java:2: error: illegal character: '#'
#include <bits/stdc++.h>
^
harbingers.java:2: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
harbingers.java:6: error: class, interface, or enum expected
typedef long long ll;
^
harbingers.java:8: error: illegal character: '#'
#define pb push_back
^
harbingers.java:8: error: class, interface, or enum expected
#define pb push_back
        ^
harbingers.java:9: error: illegal character: '#'
#define sz(x) (int)x.size()
^
harbingers.java:10: error: illegal character: '#'
#define all(x) begin(x),end(x)
^
harbingers.java:11: error: illegal character: '#'
#define lb(x,y) lower_bound(all(x),y)-begin(x)
^
harbingers.java:15: error: class, interface, or enum expected
struct Line {
^
harbingers.java:17: error: class, interface, or enum expected
    bool operator<(const Line& o) const { return k < o.k; }
    ^
harbingers.java:17: error: class, interface, or enum expected
    bool operator<(const Line& o) const { return k < o.k; }
                                                          ^
harbingers.java:18: error: class, interface, or enum expected
    bool operator<(ll x) const { return p < x; }
                                               ^
harbingers.java:21: error: class, interface, or enum expected
struct LineContainer : multiset<Line, less<>> {
^
harbingers.java:24: error: class, interface, or enum expected
    ll div(ll a, ll b) { // floored division
    ^
harbingers.java:25: error: class, interface, or enum expected
        return a / b - ((a ^ b) < 0 && a % b); }
                                               ^
harbingers.java:27: error: class, interface, or enum expected
    int getTime() { return sz(st); }
    ^
harbingers.java:27: error: class, interface, or enum expected
    int getTime() { return sz(st); }
                                   ^
harbingers.java:30: error: class, interface, or enum expected
            auto p = st.top(); st.pop();
                               ^
harbingers.java:31: error: class, interface, or enum expected
            if (p.first == 0) {
            ^
harbingers.java:33: error: class, interface, or enum expected
            } else if (p.first == 1) {
            ^
harbingers.java:35: error: class, interface, or enum expected
            } else {
            ^
harbingers.java:36: error: class, interface, or enum expected
                auto q = st.top(); st.pop();
                                   ^
harbingers.java:37: error: class, interface, or enum expected
                auto n = lower_bound(p.second);
                ^
harbingers.java:38: error: class, interface, or enum expected
                n->p = q.second.p;
                ^
harbingers.java:39: error: class, interface, or enum expected
            }
            ^
harbingers.java:44: error: class, interface, or enum expected
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        ^
harbingers.java:45: error: class, interface, or enum expected
        else x->p = div(y->m - x->m, x->k - y->k);
        ^
harbingers.java:46: error: class, interface, or enum expected
        return x->p >= y->p;
        ^
harbingers.java:47: error: class, interface, or enum expected
    }
    ^
harbingers.java:50: error: class, interface, or enum expected
        bool res = isect(x, y);
        ^
harbingers.java:51: error: class, interface, or enum expected
        st.push({2, *x});
        ^
harbingers.java:52: error: class, interface, or enum expected
        return res;
        ^
harbingers.java:53: error: class, interface, or enum expected
    }
    ^
harbingers.java:56: error: class, interface, or enum expected
        auto z = insert({k, m, 0}), y = z++, x = y;
        ^
harbingers.java:57: error: class, interface, or enum expected
        while (isectR(y, z)) st.push({0, *z}), z = erase(z);
        ^
harbingers.java:58: error: class, interface, or enum expected
        if (x != begin() && isectR(--x, y)) { st.push({0, *y}); isectR(x, y = erase(y)); }
        ^
harbingers.java:58: error: class, interface, or enum expected
        if (x != begin() && isectR(--x, y)) { st.push({0, *y}); isectR(x, y = erase(y)); }
                                                                ^
harbingers.java:58: error: class, interface, or enum expected
        if (x != begin() && isectR(--x, y)) { st.push({0, *y}); isectR(x, y = erase(y)); }
                                                                                         ^
harbingers.java:61: error: class, interface, or enum expected
    }
    ^
harbingers.java:64: error: class, interface, or enum expected
        auto l = *lower_bound(x);
        ^
harbingers.java:65: error: class, interface, or enum expected
        return l.k * x + l.m;
        ^
harbingers.java:66: error: class, interface, or enum expected
    }
    ^
harbingers.java:69: error: class, interface, or enum expected
vector<vector<int>> adj;
^
harbingers.java:70: error: class, interface, or enum expected
vector<ll> p;
^
harbingers.java:71: error: class, interface, or enum expected
LineContainer lc;
^
harbingers.java:72: error: class, interface, or enum expected
vector<ll> res;
^
harbingers.java:73: error: class, interface, or enum expected
vector<int> s, v;
^
harbingers.java:74: error: class, interface, or enum expected
void dfs(int u) {
^
harbingers.java:77: error: class, interface, or enum expected
        lc.add(p[u], -res[u]);
        ^
harbingers.java:78: error: class, interface, or enum expected
    }
    ^
harbingers.java:81: error: class, interface, or enum expected
        dfs(v);
        ^
harbingers.java:82: error: class, interface, or enum expected
        lc.setTime(t);
        ^
harbingers.java:83: error: class, interface, or enum expected
    }
    ^
harbingers.java:87: error: class, interface, or enum expected
    int N; cin >> N;
           ^
harbingers.java:88: error: class, interface, or enum expected
    adj = vector<vector<int>>(N);
    ^
harbingers.java:89: error: class, interface, or enum expected
    vector<vector<int>> edges;
    ^
harbingers.java:90: error: class, interface, or enum expected
    for (int i = 0; i < N - 1; i++) {
    ^
harbingers.java:90: error: class, interface, or enum expected
    for (int i = 0; i < N - 1; i++) {
                    ^
harbingers.java:90: error: class, interface, or enum expected
    for (int i = 0; i < N - 1; i++) {
                               ^
harbingers.java:91: error: class, interface, or enum expected
        int u, v, k; cin >> u >> v >> k; u--; v--;
                     ^
harbingers.java:91: error: class, interface, or enum expected
        int u, v, k; cin >> u >> v >> k; u--; v--;
                                         ^
harbingers.java:91: error: class, interface, or enum expected
        int u, v, k; cin >> u >> v >> k; u--; v--;
                                              ^
harbingers.java:92: error: class, interface, or enum expected
        edges.pb({u, v, k});
        ^
harbingers.java:93: error: class, interface, or enum expected
        adj[u].pb(v);
        ^
harbingers.java:94: error: class, interface, or enum expected
        adj[v].pb(u);
        ^
harbingers.java:95: error: class, interface, or enum expected
    }
    ^
harbingers.java:97: error: class, interface, or enum expected
    v = vector<int>(N);
    ^
harbingers.java:98: error: class, interface, or enum expected
    for (int i = 1; i < sz(s); i++) cin >> s[i] >> v[i];
    ^
harbingers.java:98: error: class, interface, or enum expected
    for (int i = 1; i < sz(s); i++) cin >> s[i] >> v[i];
                    ^
harbingers.java:98: error: class, interface, or enum expected
    for (int i = 1; i < sz(s); i++) cin >> s[i] >> v[i];
                               ^
harbingers.java:99: error: class, interface, or enum expected
    queue<int> q;
    ^
harbingers.java:100: error: class, interface, or enum expected
    q.push(0);
    ^
harbingers.java:101: error: class, interface, or enum expected
    vector<int> depth(N, 0);
    ^
harbingers.java:102: error: class, interface, or enum expected
    vector<int> srt;
    ^
harbingers.java:103: error: class, interface, or enum expected
    while (!q.empty()) {
    ^
harbingers.java:104: error: class, interface, or enum expected
        int u = q.front(); q.pop();
                           ^
harbingers.java:105: error: class, interface, or enum expected
        srt.pb(u);
        ^
harbingers.java:106: error: class, interface, or enum expected
        for (int v : adj[u]) {
        ^
harbingers.java:108: error: class, interface, or enum expected
            depth[v] = depth[u] + 1;
            ^
harbingers.java:109: error: class, interface, or enum expected
            q.push(v);
            ^
harbingers.java:110: error: class, interface, or enum expected
        }
        ^
harbingers.java:113: error: class, interface, or enum expected
    for (auto &edge : edges) {
    ^
harbingers.java:115: error: class, interface, or enum expected
        if (depth[v] > depth[u]) swap(u, v);
        ^
harbingers.java:116: error: class, interface, or enum expected
        p[u] = k;
        ^
harbingers.java:117: error: class, interface, or enum expected
    }
    ^
harbingers.java:120: error: class, interface, or enum expected
    }
    ^
harbingers.java:122: error: class, interface, or enum expected
    res = vector<ll>(N);
    ^
harbingers.java:123: error: class, interface, or enum expected
    dfs(0);
    ^
harbingers.java:124: error: class, interface, or enum expected
    for (int i = 1; i < sz(res); i++) {
    ^
harbingers.java:124: error: class, interface, or enum expected
    for (int i = 1; i < sz(res); i++) {
                    ^
harbingers.java:124: error: class, interface, or enum expected
    for (int i = 1; i < sz(res); i++) {
                                 ^
harbingers.java:126: error: class, interface, or enum expected
    }
    ^
harbingers.java:131: error: class, interface, or enum expected
    cin.tie(nullptr);
    ^
harbingers.java:132: error: class, interface, or enum expected
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
    ^
harbingers.java:134: error: class, interface, or enum expected
    solve();
    ^
harbingers.java:136: error: class, interface, or enum expected
    return 0;
    ^
harbingers.java:137: error: class, interface, or enum expected
}
^
97 errors