답안 #759220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
759220 2023-06-15T21:21:59 Z PurpleCrayon Magic Tree (CEOI19_magictree) C++17
47 / 100
2000 ms 35824 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(v) int(v.size())
#define ar array
const int N = 1e5+10, MOD = 1e9+7;
const ll INF = 1e18+10;

struct S {
    // i must be >= the max
    map<int, ll> mp;
    S() {
        mp[0] = 0;
    }

    void add_range(int l, int r, ll x) {
        for (auto& [k, v] : mp) {
            if (l <= k && k <= r) {
                v += x;
            }
        }
    }

    void merge(S& nxt) {
        if (sz(mp) < sz(nxt.mp)) {
            swap(mp, nxt.mp);
        }

        for (auto [k, v] : nxt.mp) {
            ll use = (--mp.upper_bound(k))->second;
            mp[k] = use;
        }

        for (auto one = nxt.mp.begin(); one != nxt.mp.end(); one++) {
            auto two = next(one);
            if (two == nxt.mp.end()) {
                // one->first, to the end
                add_range(one->first, MOD, one->second);
            } else {
                // one->first, two->first-1
                add_range(one->first, two->first - 1, one->second);
            }
        }
    }

    void add(int t, int x) {
        ll cur = (--mp.upper_bound(t))->second + x;
        auto it = mp.lower_bound(t);
        while (it != mp.end() && it->second <= cur) {
            mp.erase(it);
            it = mp.lower_bound(t);
        }

        mp[t] = cur;
    }

    ll get_ans() {
        return mp.rbegin()->second;
    }
} s[N];

int n, m, k;
vector<int> adj[N];
int t[N], a[N];

// value of ancestor has to be >= value of any thing in the subtree
void dfs(int c, int p) {
    s[c] = S();
    for (int nxt : adj[c]) if (nxt != p) {
        dfs(nxt, c);
        s[c].merge(s[nxt]);
    }

    if (t[c] != -1) s[c].add(t[c], a[c]);
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i < n; i++) {
        int p; cin >> p, --p;
        adj[p].push_back(i);
    }

    memset(t, -1, sizeof(t));
    memset(a, -1, sizeof(a));

    while (m--) {
        int c, i, x; cin >> c >> i >> x, --c;
        t[c] = i, a[c] = x;
    }

    dfs(0, -1);
    cout << s[0].get_ans() << '\n';
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 9 ms 14388 KB Output is correct
4 Correct 8 ms 14292 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 9 ms 14412 KB Output is correct
9 Correct 9 ms 14300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2082 ms 23140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14548 KB Output is correct
2 Correct 9 ms 14600 KB Output is correct
3 Correct 9 ms 14628 KB Output is correct
4 Correct 74 ms 34684 KB Output is correct
5 Execution timed out 2064 ms 35824 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 19604 KB Output is correct
2 Correct 75 ms 18920 KB Output is correct
3 Correct 56 ms 24832 KB Output is correct
4 Correct 41 ms 20420 KB Output is correct
5 Correct 58 ms 34680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 9 ms 14388 KB Output is correct
4 Correct 8 ms 14292 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 9 ms 14412 KB Output is correct
9 Correct 9 ms 14300 KB Output is correct
10 Correct 116 ms 22436 KB Output is correct
11 Correct 90 ms 21536 KB Output is correct
12 Correct 76 ms 24820 KB Output is correct
13 Correct 59 ms 20424 KB Output is correct
14 Correct 66 ms 34680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 14932 KB Output is correct
2 Correct 56 ms 16076 KB Output is correct
3 Correct 64 ms 16140 KB Output is correct
4 Correct 62 ms 16176 KB Output is correct
5 Correct 269 ms 14880 KB Output is correct
6 Correct 153 ms 19228 KB Output is correct
7 Correct 72 ms 24340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 9 ms 14388 KB Output is correct
4 Correct 8 ms 14292 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 9 ms 14412 KB Output is correct
9 Correct 9 ms 14300 KB Output is correct
10 Correct 10 ms 14548 KB Output is correct
11 Correct 9 ms 14600 KB Output is correct
12 Correct 9 ms 14628 KB Output is correct
13 Correct 74 ms 34684 KB Output is correct
14 Execution timed out 2064 ms 35824 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14292 KB Output is correct
2 Correct 8 ms 14292 KB Output is correct
3 Correct 9 ms 14388 KB Output is correct
4 Correct 8 ms 14292 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 8 ms 14292 KB Output is correct
7 Correct 8 ms 14292 KB Output is correct
8 Correct 9 ms 14412 KB Output is correct
9 Correct 9 ms 14300 KB Output is correct
10 Execution timed out 2082 ms 23140 KB Time limit exceeded
11 Halted 0 ms 0 KB -