結果

問題 No.1297 銅像
ユーザー chocoruskchocorusk
提出日時 2020-11-29 22:37:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 2,339 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 139,824 KB
実行使用メモリ 17,552 KB
最終ジャッジ日時 2023-10-11 02:39:49
合計ジャッジ時間 5,864 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 13 ms
4,352 KB
testcase_07 AC 11 ms
4,352 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 268 ms
17,044 KB
testcase_10 AC 235 ms
17,444 KB
testcase_11 AC 223 ms
9,860 KB
testcase_12 AC 206 ms
9,572 KB
testcase_13 AC 216 ms
16,712 KB
testcase_14 AC 151 ms
8,248 KB
testcase_15 AC 151 ms
8,524 KB
testcase_16 AC 152 ms
8,876 KB
testcase_17 AC 192 ms
9,872 KB
testcase_18 AC 208 ms
10,660 KB
testcase_19 AC 223 ms
17,552 KB
testcase_20 AC 248 ms
10,800 KB
testcase_21 AC 260 ms
12,256 KB
testcase_22 AC 222 ms
9,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using lll=__int128_t;
template<typename T, T xmn, T xmx, T ymx, bool ismin=true>
struct LiChaoTree{
	struct Line{
		T a, b;
		Line(T a, T b):a(a), b(b){}
		inline T get(T x) const{
			return a*x+b;
		}
	};
	struct Node{
		Node *l, *r;
		Line x;
		Node(Line x):x(x), l(nullptr), r(nullptr){}
	};
	Node *root;
	LiChaoTree():root(nullptr){}
	Node *add(Node *t, Line &x, T l, T r){
		if(!t) return new Node(x);
		bool bl=(x.get(l)<t->x.get(l))^!ismin, br=(x.get(r-1)<t->x.get(r-1))^!ismin;
		if(bl && br){
			swap(x, t->x);
			return t;
		}else if(!bl && !br) return t;
		T m=(l+r)/2;
		bool bm=(x.get(m)<t->x.get(m))^!ismin;
		if(bm) swap(x, t->x);
		if(bl!=bm) t->l=add(t->l, x, l, m);
		else t->r=add(t->r, x, m, r);
		return t;
	}
	void add(T a, T b){
		Line x=Line(a, b);
		root=add(root, x, xmn, xmx);
	}

	T get(Node *t, T l, T r, T val){
		if(!t){
			if(ismin) return ymx;
			else return -ymx;
		}
		T m=(l+r)/2;
		T ret=t->x.get(val);
		if(val<m){
			if(ismin) ret=min(ret, get(t->l, l, m, val));
			else ret=max(ret, get(t->l, l, m, val));
		}else{
			if(ismin) ret=min(ret, get(t->r, m, r, val));
			else ret=max(ret, get(t->r, m, r, val));
		}
		return ret;
	}
	T get(T val){
		return get(root, xmn, xmx, val);
	}
};
int n; ll c;
const lll INFX=1e13;
const lll INF=1e19;
ll a[100010], b[100010];
int main()
{
    cin>>n>>c;
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    LiChaoTree<lll, -INFX, INFX, INF> cht1, cht2;
    cht1.add(0, 0);
    for(int i=0; i<n; i++){
        lll dp2=(cht1.get(-2*a[i]-(2*i+1)*c)+c*i*(i+1)+2*a[i]*(i+1)+2*b[i])/2;
        cht2.add(-2*(i+1)*c+2*a[i], -(i+1)*c-2*(i+1)*a[i]+2*dp2+c*(i+1)*(i+1));
        lll dp1=(cht2.get(i+1)+c*(i+1)*(i+2))/2;
        cht1.add(i+1, c*(i+1)*(i+1)+2*dp1);
        if(i==n-1) cout<<(ll)dp1<<endl;
    }
    return 0;
}
0