結果

問題 No.703 ゴミ拾い Easy
ユーザー skylee
提出日時 2018-07-23 16:34:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 53 ms / 1,500 ms
コード長 1,919 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 47,356 KB
実行使用メモリ 13,280 KB
最終ジャッジ日時 2025-01-02 13:57:51
合計ジャッジ時間 4,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<cstdio>
#include<cctype>
#include<climits>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
using int64=long long;
const int N=3e5+1,LIM=1e5;
int a[N],x[N],y[N];
int64 f[N];
using Line=std::pair<int64,int64>;
class SegmentTree {
#define _left <<1
#define _right <<1|1
#define mid ((b+e)>>1)
private:
Line node[LIM<<2];
int64 calc(const Line &l,const int &x) const {
return l.first*x+l.second;
}
public:
void build(const int &p,const int &b,const int &e) {
node[p]={0,LLONG_MAX};
if(b==e) return;
build(p _left,b,mid);
build(p _right,mid+1,e);
}
void insert(const int &p,const int &b,const int &e,Line l1) {
if(node[p].second==LLONG_MAX) {
node[p]=l1;
return;
}
Line l2=node[p];
if(calc(l2,b)>=calc(l1,b)) std::swap(l1,l2);
if(calc(l1,e)>=calc(l2,e)) {
node[p]=l2;
return;
}
if(b==e) return;
const double c=1.*(l2.second-l1.second)/(l1.first-l2.first);
if(c<=mid) {
node[p]=l1;
insert(p _left,b,mid,l2);
} else {
node[p]=l2;
insert(p _right,mid+1,e,l1);
}
}
int64 query(const int &p,const int &b,const int &e,const int &x) const {
int64 ret=calc(node[p],x);
if(b==e) return ret;
if(x<=mid) ret=std::min(ret,query(p _left,b,mid,x));
if(x>mid) ret=std::min(ret,query(p _right,mid+1,e,x));
return ret;
}
#undef _left
#undef _right
#undef mid
};
SegmentTree t;
int main() {
const int n=getint();
for(register int i=1;i<=n;i++) a[i]=getint();
for(register int i=1;i<=n;i++) x[i]=getint();
for(register int i=1;i<=n;i++) y[i]=getint();
t.build(1,1,LIM);
for(register int i=1;i<=n;i++) {
t.insert(1,1,LIM,(Line){-2*x[i],(int64)x[i]*x[i]+(int64)y[i]*y[i]+f[i-1]});
f[i]=t.query(1,1,LIM,a[i])+(int64)a[i]*a[i];
}
printf("%lld\n",f[n]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0