This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/703
#include "../CHT-Monotone.cpp"
using ll = long long;
void solve() {
int n;
cin >> n;
vector<ll> a(n), x(n), y(n), dp(n + 1);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> x[i];
for (int i = 0; i < n; i++) cin >> y[i];
dp[0] = 0;
CHT_Monotone<ll> cht;
for (int i = 0; i < n; i++) {
cht.add(-2 * x[i], dp[i] + x[i] * x[i] + y[i] * y[i]);
dp[i + 1] = a[i] * a[i] + cht.query(a[i]);
}
cout << dp[n] << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}
#line 1 "test/CHT-Monotone.test.cpp"
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/703
#line 1 "CHT-Monotone.cpp"
#include <bits/stdc++.h>
using namespace std;
template <class T, bool isMax = false>
struct CHT_Monotone {
// 追加クエリの傾き:単調減少 xor isMax
// 取得クエリのx座標:単調増加 xor isMax
// (単調増加,単調減少)のとき:a,x -1倍
struct Line {
T a, b;
T y(T x) { return a * x + b; }
};
deque<Line> q;
bool noneed(Line a, Line b, Line c) { return (b.b - c.b) * (b.a - a.a) <= (a.b - b.b) * (c.a - b.a); }
void add(T a, T b) {
Line l = {a, b};
while (q.size() > 1 && noneed(q[q.size() - 2], q[q.size() - 1], l)) {
q.pop_back();
}
q.push_back(l);
}
T query(T x) {
if (q.empty()) return numeric_limits<T>::max() / 2;
while (q.size() > 1 && ((q[0].y(x) > q[1].y(x)) ^ isMax)) {
q.pop_front();
}
return q[0].y(x);
}
};
#line 3 "test/CHT-Monotone.test.cpp"
using ll = long long;
void solve() {
int n;
cin >> n;
vector<ll> a(n), x(n), y(n), dp(n + 1);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> x[i];
for (int i = 0; i < n; i++) cin >> y[i];
dp[0] = 0;
CHT_Monotone<ll> cht;
for (int i = 0; i < n; i++) {
cht.add(-2 * x[i], dp[i] + x[i] * x[i] + y[i] * y[i]);
dp[i + 1] = a[i] * a[i] + cht.query(a[i]);
}
cout << dp[n] << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++ | 00_sample1.txt |
![]() |
5 ms | 3 MB |
g++ | 00_sample2.txt |
![]() |
4 ms | 4 MB |
g++ | 00_sample3.txt |
![]() |
4 ms | 4 MB |
g++ | 00_sample4.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small1.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small10.txt |
![]() |
4 ms | 3 MB |
g++ | 20_small2.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small3.txt |
![]() |
4 ms | 3 MB |
g++ | 20_small4.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small5.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small6.txt |
![]() |
4 ms | 3 MB |
g++ | 20_small7.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small8.txt |
![]() |
4 ms | 4 MB |
g++ | 20_small9.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium1.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium10.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium2.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium3.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium4.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium5.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium6.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium7.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium8.txt |
![]() |
4 ms | 4 MB |
g++ | 30_medium9.txt |
![]() |
4 ms | 4 MB |
g++ | 40_large1.txt |
![]() |
52 ms | 13 MB |
g++ | 40_large10.txt |
![]() |
53 ms | 13 MB |
g++ | 40_large2.txt |
![]() |
53 ms | 13 MB |
g++ | 40_large3.txt |
![]() |
54 ms | 13 MB |
g++ | 40_large4.txt |
![]() |
54 ms | 13 MB |
g++ | 40_large5.txt |
![]() |
54 ms | 13 MB |
g++ | 40_large6.txt |
![]() |
54 ms | 13 MB |
g++ | 40_large7.txt |
![]() |
54 ms | 13 MB |
g++ | 40_large8.txt |
![]() |
53 ms | 13 MB |
g++ | 40_large9.txt |
![]() |
54 ms | 13 MB |
g++ | 50_large_binary1.txt |
![]() |
52 ms | 13 MB |
g++ | 50_large_binary10.txt |
![]() |
57 ms | 13 MB |
g++ | 50_large_binary2.txt |
![]() |
52 ms | 13 MB |
g++ | 50_large_binary3.txt |
![]() |
53 ms | 13 MB |
g++ | 50_large_binary4.txt |
![]() |
53 ms | 13 MB |
g++ | 50_large_binary5.txt |
![]() |
53 ms | 13 MB |
g++ | 50_large_binary6.txt |
![]() |
52 ms | 13 MB |
g++ | 50_large_binary7.txt |
![]() |
51 ms | 13 MB |
g++ | 50_large_binary8.txt |
![]() |
51 ms | 13 MB |
g++ | 50_large_binary9.txt |
![]() |
51 ms | 13 MB |
g++ | 99_corner1.txt |
![]() |
5 ms | 4 MB |
g++ | 99_corner2.txt |
![]() |
4 ms | 4 MB |
g++ | 99_corner3.txt |
![]() |
52 ms | 13 MB |
g++ | 99_corner4.txt |
![]() |
54 ms | 13 MB |
g++ | 99_system_test1.txt |
![]() |
5 ms | 4 MB |
g++ | 99_system_test2.txt |
![]() |
5 ms | 4 MB |
clang++ | 00_sample1.txt |
![]() |
5 ms | 4 MB |
clang++ | 00_sample2.txt |
![]() |
5 ms | 4 MB |
clang++ | 00_sample3.txt |
![]() |
5 ms | 4 MB |
clang++ | 00_sample4.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small1.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small10.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small2.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small3.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small4.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small5.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small6.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small7.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small8.txt |
![]() |
4 ms | 4 MB |
clang++ | 20_small9.txt |
![]() |
4 ms | 4 MB |
clang++ | 30_medium1.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium10.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium2.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium3.txt |
![]() |
4 ms | 4 MB |
clang++ | 30_medium4.txt |
![]() |
4 ms | 4 MB |
clang++ | 30_medium5.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium6.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium7.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium8.txt |
![]() |
5 ms | 4 MB |
clang++ | 30_medium9.txt |
![]() |
4 ms | 4 MB |
clang++ | 40_large1.txt |
![]() |
53 ms | 13 MB |
clang++ | 40_large10.txt |
![]() |
54 ms | 13 MB |
clang++ | 40_large2.txt |
![]() |
54 ms | 13 MB |
clang++ | 40_large3.txt |
![]() |
54 ms | 13 MB |
clang++ | 40_large4.txt |
![]() |
54 ms | 13 MB |
clang++ | 40_large5.txt |
![]() |
53 ms | 13 MB |
clang++ | 40_large6.txt |
![]() |
53 ms | 13 MB |
clang++ | 40_large7.txt |
![]() |
53 ms | 13 MB |
clang++ | 40_large8.txt |
![]() |
53 ms | 13 MB |
clang++ | 40_large9.txt |
![]() |
53 ms | 13 MB |
clang++ | 50_large_binary1.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary10.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary2.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary3.txt |
![]() |
53 ms | 13 MB |
clang++ | 50_large_binary4.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary5.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary6.txt |
![]() |
53 ms | 13 MB |
clang++ | 50_large_binary7.txt |
![]() |
53 ms | 13 MB |
clang++ | 50_large_binary8.txt |
![]() |
52 ms | 13 MB |
clang++ | 50_large_binary9.txt |
![]() |
52 ms | 13 MB |
clang++ | 99_corner1.txt |
![]() |
5 ms | 4 MB |
clang++ | 99_corner2.txt |
![]() |
4 ms | 4 MB |
clang++ | 99_corner3.txt |
![]() |
53 ms | 13 MB |
clang++ | 99_corner4.txt |
![]() |
54 ms | 13 MB |
clang++ | 99_system_test1.txt |
![]() |
5 ms | 4 MB |
clang++ | 99_system_test2.txt |
![]() |
5 ms | 4 MB |