結果

問題 No.1297 銅像
ユーザー chocoruskchocorusk
提出日時 2020-11-29 22:31:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 2,391 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 140,412 KB
実行使用メモリ 17,436 KB
最終ジャッジ日時 2023-10-11 02:39:41
合計ジャッジ時間 6,366 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 12 ms
4,352 KB
testcase_08 AC 13 ms
4,348 KB
testcase_09 AC 270 ms
17,052 KB
testcase_10 AC 230 ms
17,428 KB
testcase_11 AC 228 ms
9,920 KB
testcase_12 AC 211 ms
9,760 KB
testcase_13 AC 219 ms
16,772 KB
testcase_14 AC 150 ms
8,240 KB
testcase_15 AC 152 ms
8,480 KB
testcase_16 AC 153 ms
8,604 KB
testcase_17 AC 196 ms
9,880 KB
testcase_18 AC 211 ms
10,456 KB
testcase_19 AC 226 ms
17,436 KB
testcase_20 AC 251 ms
10,752 KB
testcase_21 AC 261 ms
12,252 KB
testcase_22 AC 224 ms
9,520 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:106:15: 警告: ‘dp1’ may be used uninitialized [-Wmaybe-uninitialized]
  106 |     cout<<(ll)dp1<<endl;
      |               ^~~
main.cpp:97:9: 備考: ‘dp1’ はここで定義されています
   97 |     lll dp1, dp2;
      |         ^~~

ソースコード

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 main()
{
    int n; cin>>n;
    ll c; cin>>c;
    ll a[100010], b[100010];
    for(int i=0; i<n; i++){
        cin>>a[i]>>b[i];
    }
    const lll INFX=1e13;
	const lll INF=1e19;
    LiChaoTree<lll, -INFX, INFX, INF> cht1, cht2;
    cht1.add(0, 0);
    lll dp1, dp2;
    for(int i=0; i<n; i++){
        dp2=cht1.get(-2*a[i]-(2*i+1)*c)+c*i*(i+1)+2*a[i]*(i+1)+2*b[i];
        dp2/=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));
        dp1=cht2.get(i+1)+c*(i+1)*(i+2);
        dp1/=2;
        cht1.add(i+1, c*(i+1)*(i+1)+2*dp1);
    }
    cout<<(ll)dp1<<endl;
    return 0;
}
0