Submission #115207

#TimeUsernameProblemLanguageResultExecution timeMemory
115207minhtung0404Building Bridges (CEOI17_building)C++17
0 / 100
44 ms4472 KiB
//https://oj.uz/problem/view/CEOI17_building #include<bits/stdc++.h> const int N = 1e6 + 5; const long long inf = 1e18; using namespace std; struct line { long long x, y; long long get(long long val) { return val * x + y; } line (long long x, long long y) : x(x), y(y) {} line() {} } it[4 * N]; struct LiChaoTree { #define m ((l + r) >> 1) void init() { for(int i = 0; i < 4 * N; ++i) it[i].x = 0, it[i].y = inf; } void add_line(int node, int l, int r, line u) { bool lef = u.get(l) < it[node].get(l); bool mid = u.get(m) < it[node].get(m); if(mid) swap(it[node], u); if(l == r) return; if(lef != mid) add_line(node << 1, l, m, u); else add_line(node << 1 | 1, m + 1, r, u); } long long get(int node, int l, int r, int u) { if(l == r) return it[node].get(u); if(u <= m) return min(it[node].get(u), get(node << 1, l, m, u)); return min(it[node].get(u), get(node << 1 | 1, m + 1, r, u)); } #undef m } A; int n; long long dp[N], h[N], w[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; for (int i = 1; i <= n; i++) cin >> w[i]; dp[1] = -w[1]; A.add_line(1, 0, N-1, line(-2*h[1], dp[1] + h[1] * h[1])); for (int i = 2; i <= n; i++){ dp[i] = h[i] * h[i] - w[i] + A.get(1, 0, N-1, h[i]); A.add_line(1, 0, N-1, line(-2*h[i], dp[i] + h[i] * h[i])); } for (int i = 1; i <= n; i++) dp[n] += w[i]; cout << dp[n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...