結果
問題 | No.913 木の燃やし方 |
ユーザー | snuke |
提出日時 | 2019-10-18 21:38:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 461 ms / 3,000 ms |
コード長 | 4,475 bytes |
コンパイル時間 | 2,330 ms |
コンパイル使用メモリ | 171,480 KB |
実行使用メモリ | 12,648 KB |
最終ジャッジ日時 | 2024-06-25 15:14:59 |
合計ジャッジ時間 | 18,985 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 6 ms
5,376 KB |
testcase_04 | AC | 6 ms
5,376 KB |
testcase_05 | AC | 7 ms
5,376 KB |
testcase_06 | AC | 5 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 453 ms
12,592 KB |
testcase_09 | AC | 421 ms
12,280 KB |
testcase_10 | AC | 429 ms
12,404 KB |
testcase_11 | AC | 426 ms
12,308 KB |
testcase_12 | AC | 461 ms
12,516 KB |
testcase_13 | AC | 428 ms
12,464 KB |
testcase_14 | AC | 415 ms
12,364 KB |
testcase_15 | AC | 418 ms
12,408 KB |
testcase_16 | AC | 417 ms
12,336 KB |
testcase_17 | AC | 402 ms
12,408 KB |
testcase_18 | AC | 407 ms
12,272 KB |
testcase_19 | AC | 409 ms
12,620 KB |
testcase_20 | AC | 418 ms
12,516 KB |
testcase_21 | AC | 402 ms
12,512 KB |
testcase_22 | AC | 401 ms
12,512 KB |
testcase_23 | AC | 391 ms
12,428 KB |
testcase_24 | AC | 368 ms
12,544 KB |
testcase_25 | AC | 346 ms
12,624 KB |
testcase_26 | AC | 433 ms
12,648 KB |
testcase_27 | AC | 406 ms
12,640 KB |
testcase_28 | AC | 412 ms
12,512 KB |
testcase_29 | AC | 393 ms
12,516 KB |
testcase_30 | AC | 413 ms
12,516 KB |
testcase_31 | AC | 390 ms
12,620 KB |
testcase_32 | AC | 391 ms
12,492 KB |
testcase_33 | AC | 376 ms
12,492 KB |
testcase_34 | AC | 397 ms
12,640 KB |
testcase_35 | AC | 422 ms
12,644 KB |
testcase_36 | AC | 408 ms
12,516 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:171:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 171 | scanf("%d",&n); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) #define limit(x,l,r) max(l,min(x,r)) #define lims(x,l,r) (x = max(l,min(x,r))) #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cout<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef tuple<int,int,int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; inline int in() { int x; scanf("%d",&x); return x;} template<typename T>inline istream& operator>>(istream&i,v(T)&v) {rep(j,sz(v))i>>v[j];return i;} template<typename T>string join(const v(T)&v) {stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v) {if(sz(v))o<<join(v);return o;} template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v) {return i>>v.fi>>v.se;} template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v) {return o<<v.fi<<","<<v.se;} template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;} const double eps = 1e-10; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define dame { puts("-1"); return 0;} #define yn {puts("YES");}else{puts("NO");} const int MX = 200005; // Segment tree (range add) struct F { // min func typedef ll TT; TT d; F(TT d=LINF):d(d) {} F& operator+=(const F& f) { mins(d, f.d); return *this; } F operator+(const F& f) const { return F(*this) += f;} }; struct seg { vector<F> d; int n; seg(){} seg(int mx) { n = 1; while (n < mx) n <<= 1; d = vector<F>(n<<1); } void upd(int i) { d[i] = d[i<<1]+d[i<<1|1];} F& operator[](int i) { return d[n+i];} void init() { for(int i=n-1;i;--i) upd(i);} F get(int i) { F x; for (i+=n;i;i>>=1) x += d[i]; return x; } void add(int l, int r, F f) { // cerr<<l<<" "<<r<<" "<<f.d<<endl; l += n; r += n; while (l < r) { if (l&1) d[l] += f, ++l; if (r&1) --r, d[r] += f; l >>= 1; r >>= 1; } } }; // // Convex Hull Trick typedef ll LT; typedef pair<LT,LT> LP; struct CHT { deque<LP> d; LT get(LT x) { while (sz(d) >= 2) { LT a = d[0].fi*x + d[0].se; LT b = d[1].fi*x + d[1].se; if (a <= b) break; // (min) d.pop_front(); } return d[0].fi*x + d[0].se; } void add(LP x) { // desc of x.fi (min) while (sz(d) >= 2) { LP y = d[sz(d) - 1]; LP z = d[sz(d) - 2]; if ((x.se-y.se)*(z.fi-y.fi) > (y.fi-x.fi)*(y.se-z.se)) break; // both d.pop_back(); } d.pb(x); } }; // int n; vl a; seg t; void dfs(int l, int r) { if (r-l == 0) return; if (r-l == 1) { t.add(l,r,F(a[l]+1)); return; } int c = (l+r)/2; { ll s = 0; v(LP) ls; for (int i = c; i >= l; --i) { if (i != c) s += a[i]; ls.eb(-2*(i-1),s+ll(i-1)*(i-1)); } CHT d; drep(i,sz(ls)) d.add(ls[i]); s = 0; for (int i = c; i < r; ++i) { s += a[i]; ll now = d.get(i) + (ll)i*i + s; t.add(c,i+1,F(now)); } } { ll s = 0; v(LP) ls; for (int i = c-1; i < r; ++i) { if (i != c-1) s += a[i]; ls.eb(-2*(n-i),s+ll(n-i)*(n-i)); } CHT d; drep(i,sz(ls)) d.add(ls[i]); s = 0; for (int i = c-1; i >= l; --i) { s += a[i]; int ni = n-i+1; ll now = d.get(ni) + (ll)ni*ni + s; t.add(i,c,F(now)); } } dfs(l,c); dfs(c,r); } int main() { scanf("%d",&n); a = vl(n); cin>>a; t = seg(n); dfs(0,n); rep(i,n) { ll ans = t.get(i).d; printf("%lld\n",ans); } return 0; }