結果
問題 | No.1297 銅像 |
ユーザー |
![]() |
提出日時 | 2020-11-29 22:31:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 288 ms / 2,000 ms |
コード長 | 2,391 bytes |
コンパイル時間 | 2,041 ms |
コンパイル使用メモリ | 137,000 KB |
最終ジャッジ日時 | 2025-01-16 10:17:17 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:106:15: warning: ‘dp1’ may be used uninitialized [-Wmaybe-uninitialized] 106 | cout<<(ll)dp1<<endl; | ^~~ main.cpp:97:9: note: ‘dp1’ was declared here 97 | lll dp1, dp2; | ^~~
ソースコード
#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_popcountusing 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;}