제출 #1119170

#제출 시각아이디문제언어결과실행 시간메모리
1119170Marko2604Harbingers (CEOI09_harbingers)C++14
50 / 100
164 ms50940 KiB
#include<bits/stdc++.h> #define ll long long #define MAXN 100003 using namespace std; vector<vector<pair<int,int>>>T(MAXN); int s[MAXN], v[MAXN]; struct line { int node; ll k,n; }; ll eval(ll x, line l) { return l.k*x+l.n; } ll depth[MAXN]; void depth_dfs(int node, int p) { for(auto i:T[node]) { if(i.first!=p) { depth[i.first]=(ll)i.second+depth[node]; depth_dfs(i.first, node); } } } vector<vector<line*>>lichao(262151); int loc[MAXN]; vector<ll>xx; int sz; void make_lichao(int n) { sz = (1<<((int)ceil(log2(n)))); for(int i=1;i<=n;i++) xx.push_back(v[i]); while(xx.size()<sz) xx.push_back(0); sort(xx.begin(),xx.end()); } void add_line(line *ln, int node, int l, int r) { if(node<2*sz) loc[ln->node]=node; if(lichao[node].empty()) { lichao[node].push_back(ln); return; } line *lo = lichao[node].back(); ll lold = eval(xx[l], *lo), rold = eval(xx[r], *lo); ll lnew = eval(xx[l], *ln), rnew = eval(xx[r], *ln); if(lnew>=lold && rnew>=rold) return; if(lnew<=lold && rnew<=rold) { lichao[node].push_back(ln); return; } int mid = (l+r)/2; ll mold = eval(xx[mid], *lo), mnew = eval(xx[mid], *ln); if(lnew<=lold) { if(mnew<=mold) { lichao[node].push_back(ln); add_line(lo, 2*node+1, mid+1, r); return; } else { add_line(ln, 2*node, l, mid); return; } } else { if(mnew<=mold) { lichao[node].push_back(ln); add_line(lo, 2*node, l, mid); return; } else { add_line(ln, 2*node+1, mid+1, r); return; } } return; } void pop_line(line l) { int i=loc[l.node]; while(i>1) { if(!lichao[i].empty() && lichao[i].back()->node==l.node) lichao[i].pop_back(); if(!lichao[i+1].empty() && i%2==0 && lichao[i+1].back()->node==l.node) lichao[i+1].pop_back(); if(!lichao[i-1].empty() && i%2==1 && lichao[i-1].back()->node==l.node) lichao[i-1].pop_back(); i/=2; } return; } ll get_val(ll x) { ll res = 100000000000000000; int l=0, r=sz-1, node=1; while(l<=r) { if(!lichao[node].empty()) res=min(res, eval(x, *lichao[node].back())); int mid=(l+r)/2; if(xx[mid]<=x) { l=mid+1; node=node*2+1; } else { r=mid-1; node=node*2; } } return res; } ll dp[MAXN]; void dp_dfs(int node, int p) { if(node != 1 ) dp[node]=(ll)(s[node])+(ll)(v[node])*depth[node]+get_val((ll)(v[node])); line l; l.node=node; l.k=-depth[node]; l.n=dp[node]; add_line(&l, 1, 0, sz-1); for(auto i:T[node]) { if(i.first!=p) { dp_dfs(i.first,node); } } pop_line(l); } int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int n; cin>>n; for(int i=1;i<n;i++) { int u1,v1; ll w; cin>>u1>>v1>>w; T[u1].emplace_back(v1,w); T[v1].emplace_back(u1,w); } s[1]=0, v[1]=0; for(int i=2;i<=n;i++) cin>>s[i]>>v[i]; depth[1]=0; depth_dfs(1,1); make_lichao(n); dp[1]=0; dp_dfs(1,1); for(int i=2;i<=n;i++) cout<<dp[i]<<" "; cout<<endl; return 0; }

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

harbingers.cpp: In function 'void make_lichao(int)':
harbingers.cpp:36:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     while(xx.size()<sz) xx.push_back(0);
      |           ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...