Submission #547243

#TimeUsernameProblemLanguageResultExecution timeMemory
547243pure_memMagic Tree (CEOI19_magictree)C++14
100 / 100
123 ms18860 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ll long long #define ld long double #define X first #define Y second #define MP make_pair using namespace std; const int N = 1e5 + 2; const int INF = 1e9; typedef map<int, ll> DP; void merge(DP& oth, DP& cur) { if(cur.size() < oth.size()) cur.swap(oth); for(auto [pos, val]: oth) { cur[pos] += val; } oth.clear(); } void insert(DP& cur, int pos, ll val) { cur[pos] += val; DP::iterator it = cur.upper_bound(pos); ll sum = 0; while(it != cur.end()) { if(it->second + sum > val) { it->second += sum - val; break; } else { sum += it->second; it = cur.erase(it); } } } int n, m, k; DP dp[N]; vector<int> g[N]; pair<int, int> fruit[N]; void dfs(int v) { for(int to: g[v]) { dfs(to); merge(dp[to], dp[v]); } insert(dp[v], fruit[v].X, fruit[v].Y); } int main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(int i = 2, v;i <= n;i++) { cin >> v; g[v].push_back(i); } for(int i = 1;i <= m;i++) { int v, d, w; cin >> v >> d >> w; fruit[v] = {d, w}; } dfs(1); ll res = 0; for(auto [pos, val]: dp[1]) res += val; cout << res; }

Compilation message (stderr)

magictree.cpp: In function 'void merge(DP&, DP&)':
magictree.cpp:21:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |  for(auto [pos, val]: oth) {
      |           ^
magictree.cpp: In function 'int main()':
magictree.cpp:75:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |  for(auto [pos, val]: dp[1])
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...