제출 #474847

#제출 시각아이디문제언어결과실행 시간메모리
474847aniervsHarbingers (CEOI09_harbingers)C++17
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = (int)2e5 + 5; struct PersistentLiChaoTree{ struct line{ ll m, b; line(){ m = b = 1e9;} line(ll _m, ll _b){ m = _m, b = _b; } ll eval(ll x){ return m * x + b; } }; struct node{ node * l, * r; line L; node(){ l = 0, r = 0, L = line(); } node(node * _l, node * _r, line _L){ l = _l, r = _r, L = _L; } }; node * add_line(node * u, int l, int r, line L){ node * v = new node(0, 0, L); if(u) v = node(u->l, u->r, u->L); int m = (l + r)>>1; bool lef = L.eval(l) < v->L.eval(l); bool mid = L.eval(m) < v->L.eval(m); if(mid) swap(v->L, L); if(r - l == 1) return v; if(lef != mid) { v->l = add_line(v->l, l, m, L); } else{ v->r = add_line(v->r, m, r, L); } return v; } ll get(node * u, int l, int r, int x) { int m = (l + r) / 2; if(r - l == 1) return u->L.eval(x); if(x < m){ ll q2 = (u->l) ? get(u->l, l, m, x) : LLONG_MAX; return min(q2, u->L.eval(x)); } ll q2 = (u->r) ? get(u->r, m, r, x) : LLONG_MAX; return min(q2, u->L.eval(x)); } vector<node*> roots; PersistentLiChaoTree(){ node * u = new node(0, 0, line()); roots.push_back(u); } int update(int old, line l){ roots.push_back(add_line(roots[old], 0, 1e9, l)); return (int)roots.size() - 1; } ll query(int id, ll x){ return get(roots[id], 0, 1e9, x); } } lt; vector<pair<int,int>> G[maxn]; ll speed[maxn], start[maxn], dp[maxn], sumW[maxn]; int n, par[maxn]; int pos[maxn]; void dfs(int u){ pos[u] = lt.update(pos[par[u]], PersistentLiChaoTree::line(-sumW[u], dp[u])); for(auto [v, w]:G[u]){ if(v == par[u]) continue; sumW[v] = sumW[u] + w; par[v] = u; dp[v] = sumW[v] * speed[v] + start[v] + lt.query(pos[u], speed[v]); dfs(v); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i < n; i++){ int u, v, w; cin >> u >> v >> w; G[u].push_back({v, w}); G[v].push_back({u, w}); } for(int i = 2; i <= n; i++) cin >> start[i] >> speed[i]; dfs(1); for(int i = 2; i <= n; i++) cout << dp[i] << ' '; cout << endl; return 0; } /* 5 1 2 20 2 3 12 2 4 1 4 5 3 26 9 1 10 500 2 2 30 */

컴파일 시 표준 에러 (stderr) 메시지

harbingers.cpp: In member function 'PersistentLiChaoTree::node* PersistentLiChaoTree::add_line(PersistentLiChaoTree::node*, int, int, PersistentLiChaoTree::line)':
harbingers.cpp:31:15: error: cannot convert 'PersistentLiChaoTree::node' to 'PersistentLiChaoTree::node*' in assignment
   31 |           v = node(u->l, u->r, u->L);
      |               ^~~~~~~~~~~~~~~~~~~~~~
      |               |
      |               PersistentLiChaoTree::node