#include // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2") #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define yn(joken) cout<<((joken) ? "Yes" : "No")<<"\n" #define YN(joken) cout<<((joken) ? "YES" : "NO")<<"\n" using namespace std; using ll = long long; using vi = vector; using vl = vector; using vs = vector; using vc = vector; using vd = vector; using vld = vector; using vvi = vector>; using vvl = vector>; using vvs = vector>; using vvc = vector>; using vvd = vector>; using vvld = vector>; using vvvi = vector>>; using vvvl = vector>>; using vvvvi = vector>>>; using vvvvl = vector>>>; using pii = pair; using pll = pair; const int INF = 1e9; const ll LINF = 2e18; template bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } bool ispow2(int i) { return i && (i & -i) == i; } bool ispow2(ll i) { return i && (i & -i) == i; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template istream& operator>>(istream& is, vector& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < int(v.size()) - 1) os << ' '; } return os; } static uint32_t RandXor(){ static uint32_t x=123456789; static uint32_t y=362436069; static uint32_t z=521288629; static uint32_t w=88675123; uint32_t t; t=x^(x<<11); x=y; y=z; z=w; return w=(w^(w>>19))^(t^(t>>8)); } // DynamicLiChaoTree LCT(ll min_index,ll max_index); などする // xの動きうる最大範囲が[min_index,max_index) // void add_line(T a,T b): 直線 ax+b を追加 // void add_segment_line(T Llim,T Rlim,T a,T b): [Llim,Rlim]の線分 ax+b を追加 // T get(T x): min(ax+b) を返す template struct DynamicLiChaoTree{ private: struct Line{ T slope, intercept; Line() : slope(0), intercept(numeric_limits::max() / 2) {} Line(T a, T b):slope(a),intercept(b) {} T f(T x) {return slope * x + intercept;} }; struct node { Line line; node *left, *right; node(Line line): line(line), left(nullptr), right(nullptr) {} }; const long long min_index,max_index; node* root; node* add_line(node* &t, long long l, long long r, Line line) const { if(l == r) return nullptr; if (!t) { t = new node(line); return t; } long long m = (l + r) >> 1; bool L = (line.f(l) <= t->line.f(l)); bool M = (line.f(m) <= t->line.f(m)); bool R = (line.f(r) <= t->line.f(r)); if(L && R){ t->line = line; return t; } if(!L && !R){ return t; } if(M){ swap(t->line, line); } if(L != M){ t->left=add_line(t->left, l, m, line); } else{ t->right=add_line(t->right, m, r, line); } return t; } node* add_segment_line(node* t, long long Llim, long long Rlim, long long l, long long r, Line line){ if(r < Llim || Rlim < l) return t; if(Llim <= l && r <= Rlim) return add_line(t, l, r, line); if(t == nullptr) t = new node(); long long m = (l + r) >> 1; t->left = add_segment_line(t, Llim, Rlim, l, m, line); t->right = add_segment_line(t, Llim, Rlim, m, r, line); return t; } public: DynamicLiChaoTree(T min_index,T max_index): min_index(min_index), max_index(max_index), root(nullptr){} void add_line(T a, T b){ Line line = Line{a, b}; add_line(root, min_index, max_index, line); } void add_segment_line(T Llim, T Rlim, T a, T b){ Line line = Line{a,b}; add_segment_line(root, Llim, Rlim, min_index, max_index, line); } T get(long long x){ node *t = root; long long l = min_index, r = max_index; T ret = numeric_limits::max() / 2; while(r - l > 0 && t != nullptr){ long long m = (l + r) >> 1; ret = min(ret, t->line.f(x)); if(x < m){ r = m; t = t->left; } else{ l = m; t = t->right; } } return ret; } }; void solve(){ ll N; cin>>N; vl A(N),X(N),Y(N); cin>>A>>X>>Y; vl DP(N+1); DynamicLiChaoTree LCT(0,1e6); DP[0]=0; for(ll i=1;i<=N;i++){ LCT.add_line(-2*X[i-1],X[i-1]*X[i-1]+Y[i-1]*Y[i-1]+DP[i-1]); DP[i]=LCT.get(A[i-1])+A[i-1]*A[i-1]; } cout<