結果

問題 No.703 ゴミ拾い Easy
ユーザー tjaketjake
提出日時 2018-11-09 00:57:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,115 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 88,744 KB
実行使用メモリ 24,664 KB
最終ジャッジ日時 2024-04-30 22:47:08
合計ジャッジ時間 14,176 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
12,928 KB
testcase_01 AC 10 ms
12,800 KB
testcase_02 AC 9 ms
12,800 KB
testcase_03 AC 10 ms
12,928 KB
testcase_04 AC 9 ms
12,800 KB
testcase_05 AC 9 ms
12,800 KB
testcase_06 AC 10 ms
12,928 KB
testcase_07 AC 9 ms
12,928 KB
testcase_08 AC 10 ms
12,800 KB
testcase_09 AC 9 ms
12,672 KB
testcase_10 AC 9 ms
12,928 KB
testcase_11 AC 10 ms
13,056 KB
testcase_12 AC 9 ms
12,928 KB
testcase_13 AC 9 ms
12,928 KB
testcase_14 AC 10 ms
12,928 KB
testcase_15 AC 10 ms
12,928 KB
testcase_16 AC 11 ms
12,928 KB
testcase_17 AC 10 ms
12,928 KB
testcase_18 AC 10 ms
12,928 KB
testcase_19 AC 10 ms
12,928 KB
testcase_20 AC 10 ms
12,928 KB
testcase_21 AC 11 ms
12,928 KB
testcase_22 AC 11 ms
12,928 KB
testcase_23 AC 11 ms
12,928 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 AC 10 ms
12,672 KB
testcase_45 AC 9 ms
12,800 KB
testcase_46 RE -
testcase_47 RE -
testcase_48 AC 11 ms
12,928 KB
testcase_49 AC 11 ms
12,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
#include<utility>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 600004
typedef pair<ll, ll> line;

class LiChaoTree {
  int n;
  ll xs[N];
  line data[N];
  bool u[N];

  ll f(line &l, ll x) {
    return l.first*x + l.second;
  }

  void _add_line(line ln) {
    int k = 0, l = 0, r = n;
    while(1) {
      int m = (l + r) / 2;
      if(!u[k]) {
        data[k] = ln;
        u[k] = true;
        return;
      }

      ll lx = xs[l], mx = xs[m], rx = xs[r-1];
      bool left = (f(ln, lx) < f(data[k], lx));
      bool mid = (f(ln, mx) < f(data[k], mx));
      bool right = (f(ln, rx) < f(data[k], rx));
      if(left && right) {
        data[k] = ln;
        return;
      }
      if(!left && !right) {
        return;
      }
      if(mid) {
        swap(data[k], ln);
      }
      if(left != mid) {
        k = 2*k+1; r = m;
      } else {
        k = 2*k+2; l = m;
      }
    }
  }

  ll _query(int k, ll x) {
    k += n - 1;
    ll s = u[k] ? f(data[k], x) : INFLL;
    while(k) {
      k = (k - 1) / 2;
      if(u[k]) {
        ll r = f(data[k], x);
        s = mind(s, r);
      }
    }
    return s;
  }

public:
  LiChaoTree(vector<ll> &ps) {
    int n0 = ps.size();
    n = 1;
    while(n < n0) n <<= 1;

    rep(i, n) u[i] = false;
    rep(i, n0) xs[i] = ps[i];
    repl(i, n0, n-1) xs[i] = INF;
  }

  void add_line(ll p, ll q) {
    _add_line(line(p, q));
  }

  ll query(int i) {
    return _query(i, xs[i]);
  }
};

int n;
ll x[N], y[N];

int main() {
  cin >> n;
  vector<ll> a;
  rep(i, n) {
    ll v;
    cin >> v;
    a.push_back(v);
  }
  rep(i, n) cin >> x[i];
  rep(i, n) cin >> y[i];

  LiChaoTree lct(a);
  ll v = 0;
  rep(i, n) {
    lct.add_line(-2*x[i], x[i]*x[i] + y[i]*y[i] + v);
    v = lct.query(i) + a[i]*a[i];
  }
  cout << v << endl;
  return 0;
}
0