結果

問題 No.704 ゴミ拾い Medium
ユーザー muminmumin
提出日時 2020-12-28 06:11:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 1,500 ms
コード長 2,318 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 174,868 KB
実行使用メモリ 45,568 KB
最終ジャッジ日時 2024-04-17 02:00:17
合計ジャッジ時間 11,279 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
35,840 KB
testcase_01 AC 30 ms
35,840 KB
testcase_02 AC 36 ms
35,968 KB
testcase_03 AC 32 ms
35,968 KB
testcase_04 AC 29 ms
35,968 KB
testcase_05 AC 30 ms
35,968 KB
testcase_06 AC 30 ms
35,840 KB
testcase_07 AC 29 ms
35,968 KB
testcase_08 AC 30 ms
35,968 KB
testcase_09 AC 29 ms
35,968 KB
testcase_10 AC 29 ms
35,968 KB
testcase_11 AC 30 ms
35,968 KB
testcase_12 AC 30 ms
35,840 KB
testcase_13 AC 35 ms
35,968 KB
testcase_14 AC 36 ms
36,096 KB
testcase_15 AC 38 ms
36,096 KB
testcase_16 AC 36 ms
36,096 KB
testcase_17 AC 36 ms
36,096 KB
testcase_18 AC 36 ms
36,096 KB
testcase_19 AC 36 ms
36,096 KB
testcase_20 AC 36 ms
35,968 KB
testcase_21 AC 37 ms
36,096 KB
testcase_22 AC 37 ms
36,224 KB
testcase_23 AC 36 ms
35,968 KB
testcase_24 AC 223 ms
45,440 KB
testcase_25 AC 223 ms
45,312 KB
testcase_26 AC 222 ms
45,440 KB
testcase_27 AC 222 ms
45,440 KB
testcase_28 AC 222 ms
45,440 KB
testcase_29 AC 220 ms
45,440 KB
testcase_30 AC 223 ms
45,312 KB
testcase_31 AC 226 ms
45,568 KB
testcase_32 AC 222 ms
45,312 KB
testcase_33 AC 222 ms
45,440 KB
testcase_34 AC 155 ms
45,440 KB
testcase_35 AC 156 ms
45,440 KB
testcase_36 AC 158 ms
45,312 KB
testcase_37 AC 158 ms
45,440 KB
testcase_38 AC 158 ms
45,440 KB
testcase_39 AC 156 ms
45,312 KB
testcase_40 AC 156 ms
45,440 KB
testcase_41 AC 158 ms
45,440 KB
testcase_42 AC 157 ms
45,312 KB
testcase_43 AC 156 ms
45,440 KB
testcase_44 AC 34 ms
35,968 KB
testcase_45 AC 34 ms
35,968 KB
testcase_46 AC 202 ms
45,440 KB
testcase_47 AC 208 ms
45,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;

const ll INF = 1e18;

struct LiChaoTree{
	int size;
	vector<pll> seg;

	LiChaoTree(){}
	LiChaoTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}

	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = make_pair(0, INF);
	}
	ll calc(pll f, ll x)
	{
		return f.first * x + f.second;
	}
	ll query(int x) //xにおける最小値を取得
	{
		int i = x + (1 << size);
		ll ret = INF;
		while(i >= 1){
			ret = min(ret, calc(seg[i], x));
			i /= 2;
		}
		return ret;
	}
	void add(int k, int l, int r, pll f)
	{
		int m = (l+r)/2;
		if(calc(f, m) < calc(seg[k], m)) swap(seg[k], f);
		bool L = (calc(f, l) < calc(seg[k], l)), R = (calc(f, r) < calc(seg[k], r));
		if(L == R) return;
		if(L) add(k*2, l, m, f);
		if(R) add(k*2+1, m+1, r, f);
	}
	void addSegment(int a, int b, int k, int l, int r, pll f)
	{
		if(b < l || r < a) return;
		if(a <= l && r <= b){
			add(k, l, r, f);
			return;
		}
		addSegment(a, b, k*2, l, (l+r)/2, f);
		addSegment(a, b, k*2+1, (l+r)/2+1, r, f);
	}
	void addSegment(int a, int b, ll p, ll q) //区間[a, b]に線分px+qを追加
	{
		addSegment(a, b, 1, 0, (1<<size)-1, make_pair(p, q));
	}
	void addLine(ll p, ll q) //直線px+qを追加
	{
		return addSegment(0, (1<<size)-1, p, q);
	}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    V<ll> a(n), x(n), y(n);
    rep(i,n) cin >> a[n-1-i];
    rep(i,n) cin >> x[n-1-i];
    rep(i,n) cin >> y[n-1-i];
    LiChaoTree lct(20);
    lct.init();
    V<ll> dp(n+1);
    dp[0] = 0;
    lct.addSegment(a[0], (1<<20)-1, 1, -a[0]+dp[0]);
    lct.addSegment(0, a[0]-1, -1, a[0]+dp[0]);
    for(int i = 1; i <= n; i++){
        dp[i] = lct.query(x[i-1]) + y[i-1];
        if(i < n){
            lct.addSegment(a[i], (1<<20)-1, 1, -a[i]+dp[i]);
            lct.addSegment(0, a[i]-1, -1, a[i]+dp[i]);
        }
    }
    cout << dp[n] << endl;
}
0