結果
問題 | No.703 ゴミ拾い Easy |
ユーザー |
![]() |
提出日時 | 2018-06-16 01:57:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,702 bytes |
コンパイル時間 | 1,791 ms |
コンパイル使用メモリ | 177,624 KB |
実行使用メモリ | 12,872 KB |
最終ジャッジ日時 | 2024-09-13 20:39:15 |
合計ジャッジ時間 | 8,963 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 45 WA * 1 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef signed long long ll;#undef _P#define _P(...) (void)printf(__VA_ARGS__)#define FOR(x,to) for(x=0;x<(to);x++)#define FORR(x,arr) for(auto& x:arr)#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)#define ALL(a) (a.begin()),(a.end())#define ZERO(a) memset(a,0,sizeof(a))#define MINUS(a) memset(a,0xff,sizeof(a))//-------------------------------------------------------template<typename V> struct ConvexHullOnline {const V inf=1LL<<40+1;const int cmptype=1; // 0-max 1-minmap<V,V> Q,PR; // Q[a]=b -> a*x+b, P[a]=c ax+b is best unti x<=c PR[c]=aunordered_map<V,V> P;ConvexHullOnline() { Q[inf]=-inf*inf; Q[-inf]=inf*inf;}int ok(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or minif(A.first==-inf && C.first==inf) return 1;return ((__int128_t)(B.second-A.second)*(B.first-C.first)<=(__int128)(C.second-B.second)*(A.first-B.first));}bool bad(typename map<V,V>::iterator it) {if(it==Q.begin() || next(it)==Q.end() || next(it)->first==inf || prev(it)->first==-inf) return false;return ok(*prev(it),*it,*next(it))==0;}void erase(typename map<V,V>::iterator it) { PR.erase(P[it->first]); P.erase(it->first); Q.erase(it);}void update(typename map<V,V>::iterator it) {if(next(it)==Q.end() || it==Q.begin()) return;auto it2=next(it);if(it2->first==inf) {P[it->first]=inf; PR[inf]=it->first;}else {P[it->first]=(it2->second-it->second)/(it->first-it2->first);PR[P[it->first]]=it->first;}}void add(V a, V b) { // add ax+bif(cmptype) a=-a, b=-b;if(Q.count(a)) if(Q[a]==b || Q[a]>b) return;Q[a]=b;auto it=Q.find(a);if(bad(it)) return (void)Q.erase(it);while(bad(next(it))) erase(next(it));while(bad(prev(it))) erase(prev(it));PR.erase(P[it->first]); P.erase(it->first);if(prev(it)!=Q.begin()) PR.erase(P[prev(it)->first]); P.erase(prev(it)->first);update(it);update(prev(it));}V query(V x) {auto it=PR.lower_bound(x);return (it->second*x+Q[it->second])*(cmptype?-1:1);}};template<typename V> struct ConvexHull {deque<pair<V,V>> Q;int cmptype=1; // 0-max 1-minV calc(pair<V,V> p, V x) {return p.first*x+p.second;}int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or minreturn cmptype^((B.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-B.first));}void add(V a, V b) { // add ax+bQ.push_back({a,b});int v;while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))Q[v-2]=Q[v-1], Q.pop_back();}void add(vector<pair<V,V>> v) {sort(v.begin(),v.end());if(cmptype==1) reverse(v.begin(),v.end());for(auto r=v.begin();r!=v.end();r++) add(r->first,r->second);}V query(V x) {int L=-1,R=Q.size()-1;while(R-L>1) {int M=(L+R)/2;(cmptype^((calc(Q[M],x)<calc(Q[M+1],x)))?L:R)=M;}//cout<<L<<":"<<R<<":"<<Q.size()<<":"<<Q[R].first<<"*"<<x<<"+"<<Q[R].second<<" == "<<calc(Q[R],x)<<endl;return calc(Q[R],x);}};int N;ll A[303030];ll X[303030];ll Y[303030];ll D[303030];//ConvexHull<ll> cht;ConvexHullOnline<ll> cht;void solve() {int i,j,k,l,r,x,y; string s;cin>>N;FOR(i,N) cin>>A[i];FOR(i,N) cin>>X[i];FOR(i,N) cin>>Y[i];FOR(i,N) {//cout<<"add "<<-2*X[i]<<" x + "<<D[i]+X[i]*X[i]+Y[i]*Y[i]<<endl;cht.add(-2*X[i],D[i]+X[i]*X[i]+Y[i]*Y[i]);//FORR(q,cht.Q) cout<<" "<<q.first<<" x+ "<<q.second<<endl;D[i+1]=cht.query(A[i])+A[i]*A[i];//cout<<D[i+1]<<endl;}cout<<D[N]<<endl;}int main(int argc,char** argv){string s;int i;if(argc==1) ios::sync_with_stdio(false), cin.tie(0);FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);cout.tie(0); solve(); return 0;}