Submission #1997374


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<typename T> struct CHT {
    typedef pair<T, T> P; vector<P> st; int sz = -1; int ptr;
    using ld = long double;
    ld cross(P l1, P l2) {return ((ld)l2.second - (ld)l1.second) / ((ld)l2.first - (ld)l1.first);}
    bool chk(P l1, P l2, P l3) {return (cross(l1, l3) - cross(l1, l2))>(1e-18);}
    T f(P L, T x) { return L.first * x + L.second; }

    void init(int n) { st.resize(n + 5); sz = 0; ptr = 1; }
    void add(T m, T n) {while(sz>=2&&chk(st[sz-1], st[sz], P(m, n))) --sz; st[++sz] = P(m, n); }
    T get(T x) {while (ptr<sz && f(st[ptr], x)>f(st[ptr + 1], x))ptr++;return f(st[ptr], x);}};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



int N;
ll A[201010];
CHT<ll> cht;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    cht.init(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cht.add(-2 * i, A[i] + 1LL * i * i);
    rep(i, 0, N) {
        ll ans = cht.get(i) + 1LL * i * i;
        printf("%lld\n", ans);
    }
}

Submission Info

Submission Time
Task C - スペースエクスプローラー高橋君
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2248 Byte
Status AC
Exec Time 51 ms
Memory 7040 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 35
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 1 ms 256 KB
01.txt AC 2 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 2 ms 256 KB
04.txt AC 2 ms 256 KB
05.txt AC 2 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 17 ms 2304 KB
08.txt AC 12 ms 1664 KB
09.txt AC 6 ms 896 KB
10.txt AC 5 ms 768 KB
11.txt AC 3 ms 384 KB
12.txt AC 8 ms 1152 KB
13.txt AC 24 ms 3200 KB
14.txt AC 23 ms 3072 KB
15.txt AC 23 ms 3072 KB
16.txt AC 2 ms 384 KB
17.txt AC 50 ms 6400 KB
18.txt AC 49 ms 6400 KB
19.txt AC 49 ms 6400 KB
20.txt AC 49 ms 6400 KB
21.txt AC 48 ms 6912 KB
22.txt AC 50 ms 7040 KB
23.txt AC 51 ms 7040 KB
24.txt AC 49 ms 6912 KB
25.txt AC 50 ms 6912 KB
26.txt AC 50 ms 6912 KB
27.txt AC 50 ms 6912 KB
28.txt AC 50 ms 6912 KB
29.txt AC 37 ms 6272 KB
30.txt AC 37 ms 6272 KB
31.txt AC 41 ms 6784 KB
32.txt AC 42 ms 6784 KB