# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
718676 | Ozy | Harbingers (CEOI09_harbingers) | C++17 | 1083 ms | 28292 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define lli long long int
#define pll pair<lli,lli>
#define MAX 100000
// para los hijos
#define des first
#define w second
//para el arreglo de lin
#define prep first
#define vel second
//para el convex hull
#define m first
#define ord second
lli n,a,b,c;
vector<pair<int, int> > hijos[MAX+2];
pair<int, int> lin[MAX+2];
pll ch[MAX+2];
long double anterior[MAX+2];
int ancestros[MAX+2][19];
lli dp[MAX+2],prof[MAX+2];
long double cruce(pll a, pll b) {
long double u = a.ord - b.ord;
long double v = b.m - a.m;
u /= v;
return u;
}
void solve(int pos, int padre, lli p) {
prof[pos] = p;
// responde la pregunta para mi posicion
lli x = padre;
repa(i,18,0) if (anterior[ancestros[x][i]] >= lin[pos].vel) x = ancestros[x][i];
if (anterior[x] >= lin[pos].vel) x = ancestros[x][0];
//FUNCIONA while (anterior[x] >= lin[pos].vel) x = ancestros[x][0];
dp[pos] = lin[pos].prep + prof[pos]*lin[pos].vel + dp[x] - prof[x]*lin[pos].vel;
//hago mi propia línea
ch[pos].ord = dp[pos];
ch[pos].m = -prof[pos];
//me integro en el convex hull trick
x = padre;
while (x)
if (cruce(ch[pos], ch[x]) <= anterior[x]) x = ancestros[x][0];
else break;
ancestros[pos][0] = x;
anterior[pos] = cruce(ch[pos], ch[x]);
repa(i,1,18) {
ancestros[pos][i] = ancestros[x][i-1];
x = ancestros[pos][i];
}
for(auto h : hijos[pos]) {
if (h.des == padre) continue;
solve(h.des,pos,p+h.w);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i,2,n) {
cin >> a >> b >> c;
hijos[a].push_back({b,c});
hijos[b].push_back({a,c});
}
rep(i,2,n) cin >> lin[i].prep >> lin[i].vel;
for (auto h : hijos[1]) {
solve(h.des,1,h.w);
}
rep(i,2,n) cout << dp[i] << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |