Submission #494932

# Submission time Handle Problem Language Result Execution time Memory
494932 2021-12-17T15:09:19 Z YJU Magic Tree (CEOI19_magictree) C++17
100 / 100
124 ms 40796 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops, no-stack-protector, Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll INF = (1LL<<60);
const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ld pi = acos(-1);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
#define setp setprecision

typedef map<ll, ll> mll;

ll d[N], w[N], n, m, t;
vector<ll> v[N];
mll *dp[N];

void insert(mll *a, pll k) {
	ll last = k.se;
	for (auto i = (*a).lwb(k.fi+1);i != (*a).end(); i = (*a).lwb(i->fi+1)) {
		if (i->se > last) {
			i->se -= last;
			break;
		} else {
			last -= i->se;
			(*a).erase(i);
		}
	}
	(*a)[k.fi] += k.se;
}

mll* mg(mll *a, mll *b) {
	if (SZ((*a)) > SZ((*b))) swap(a, b);
	for (auto i : (*a)) (*b)[i.fi] += i.se;
	return b;
}

void DFS(ll now) {
	dp[now] = new mll;
	for (ll to : v[now]) {
		DFS(to);
		dp[now] = mg(dp[now], dp[to]);
	}
	if (w[now]) {
		insert(dp[now], {d[now], w[now]});
	}
}


int main () {
	ios_base::sync_with_stdio(0);
	cin >> n >> m >> t;
	for (ll i = 2, x;i <= n; ++i) {
		cin >> x;
		v[x].pb(i);
	}
	for (ll i = 0, x;i < m; ++i) {
		cin >> x;
		cin >> d[x] >> w[x];
	}
	DFS(1);
	ll ans = 0;
	for (auto i : (*dp[1])) {
		ans += i.se;
	}
	cout << ans << "\n";
	return 0;
}

Compilation message

magictree.cpp:2:63: warning: bad option '-f no-stack-protector' to pragma 'optimize' [-Wpragmas]
    2 | #pragma GCC optimize("unroll-loops, no-stack-protector, Ofast")
      |                                                               ^
magictree.cpp:2:63: warning: bad option '-f Ofast' to pragma 'optimize' [-Wpragmas]
magictree.cpp:25:26: warning: bad option '-f no-stack-protector' to attribute 'optimize' [-Wattributes]
   25 | void insert(mll *a, pll k) {
      |                          ^
magictree.cpp:25:26: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
magictree.cpp:39:23: warning: bad option '-f no-stack-protector' to attribute 'optimize' [-Wattributes]
   39 | mll* mg(mll *a, mll *b) {
      |                       ^
magictree.cpp:39:23: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
magictree.cpp:45:16: warning: bad option '-f no-stack-protector' to attribute 'optimize' [-Wattributes]
   45 | void DFS(ll now) {
      |                ^
magictree.cpp:45:16: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
magictree.cpp:57:11: warning: bad option '-f no-stack-protector' to attribute 'optimize' [-Wattributes]
   57 | int main () {
      |           ^
magictree.cpp:57:11: warning: bad option '-f Ofast' to attribute 'optimize' [-Wattributes]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2672 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 21292 KB Output is correct
2 Correct 41 ms 19092 KB Output is correct
3 Correct 124 ms 40796 KB Output is correct
4 Correct 88 ms 23440 KB Output is correct
5 Correct 112 ms 24640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2764 KB Output is correct
2 Correct 2 ms 2764 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 51 ms 20608 KB Output is correct
5 Correct 78 ms 26424 KB Output is correct
6 Correct 66 ms 22540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 16768 KB Output is correct
2 Correct 62 ms 16068 KB Output is correct
3 Correct 49 ms 17348 KB Output is correct
4 Correct 41 ms 17580 KB Output is correct
5 Correct 50 ms 20600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2672 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 70 ms 19536 KB Output is correct
11 Correct 59 ms 18644 KB Output is correct
12 Correct 50 ms 17356 KB Output is correct
13 Correct 40 ms 17716 KB Output is correct
14 Correct 43 ms 20548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4940 KB Output is correct
2 Correct 36 ms 13252 KB Output is correct
3 Correct 37 ms 13260 KB Output is correct
4 Correct 34 ms 13256 KB Output is correct
5 Correct 15 ms 12412 KB Output is correct
6 Correct 30 ms 14836 KB Output is correct
7 Correct 30 ms 16968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2672 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2764 KB Output is correct
11 Correct 2 ms 2764 KB Output is correct
12 Correct 2 ms 2764 KB Output is correct
13 Correct 51 ms 20608 KB Output is correct
14 Correct 78 ms 26424 KB Output is correct
15 Correct 66 ms 22540 KB Output is correct
16 Correct 70 ms 19536 KB Output is correct
17 Correct 59 ms 18644 KB Output is correct
18 Correct 50 ms 17356 KB Output is correct
19 Correct 40 ms 17716 KB Output is correct
20 Correct 43 ms 20548 KB Output is correct
21 Correct 17 ms 7544 KB Output is correct
22 Correct 83 ms 22156 KB Output is correct
23 Correct 75 ms 25288 KB Output is correct
24 Correct 112 ms 33608 KB Output is correct
25 Correct 73 ms 22800 KB Output is correct
26 Correct 94 ms 23240 KB Output is correct
27 Correct 75 ms 20720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 1 ms 2672 KB Output is correct
5 Correct 1 ms 2636 KB Output is correct
6 Correct 1 ms 2636 KB Output is correct
7 Correct 1 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 58 ms 21292 KB Output is correct
11 Correct 41 ms 19092 KB Output is correct
12 Correct 124 ms 40796 KB Output is correct
13 Correct 88 ms 23440 KB Output is correct
14 Correct 112 ms 24640 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 2 ms 2764 KB Output is correct
17 Correct 2 ms 2764 KB Output is correct
18 Correct 51 ms 20608 KB Output is correct
19 Correct 78 ms 26424 KB Output is correct
20 Correct 66 ms 22540 KB Output is correct
21 Correct 67 ms 16768 KB Output is correct
22 Correct 62 ms 16068 KB Output is correct
23 Correct 49 ms 17348 KB Output is correct
24 Correct 41 ms 17580 KB Output is correct
25 Correct 50 ms 20600 KB Output is correct
26 Correct 70 ms 19536 KB Output is correct
27 Correct 59 ms 18644 KB Output is correct
28 Correct 50 ms 17356 KB Output is correct
29 Correct 40 ms 17716 KB Output is correct
30 Correct 43 ms 20548 KB Output is correct
31 Correct 7 ms 4940 KB Output is correct
32 Correct 36 ms 13252 KB Output is correct
33 Correct 37 ms 13260 KB Output is correct
34 Correct 34 ms 13256 KB Output is correct
35 Correct 15 ms 12412 KB Output is correct
36 Correct 30 ms 14836 KB Output is correct
37 Correct 30 ms 16968 KB Output is correct
38 Correct 17 ms 7544 KB Output is correct
39 Correct 83 ms 22156 KB Output is correct
40 Correct 75 ms 25288 KB Output is correct
41 Correct 112 ms 33608 KB Output is correct
42 Correct 73 ms 22800 KB Output is correct
43 Correct 94 ms 23240 KB Output is correct
44 Correct 75 ms 20720 KB Output is correct
45 Correct 18 ms 8016 KB Output is correct
46 Correct 71 ms 23100 KB Output is correct
47 Correct 86 ms 26552 KB Output is correct
48 Correct 123 ms 36680 KB Output is correct
49 Correct 94 ms 23492 KB Output is correct
50 Correct 108 ms 24312 KB Output is correct
51 Correct 90 ms 21580 KB Output is correct