제출 #87939

#제출 시각아이디문제언어결과실행 시간메모리
87939vanbang9710수열 (APIO14_sequence)C++14
0 / 100
90 ms82008 KiB
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<climits>
#include<cstring>
#include<iomanip>
#include<string>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<algorithm>
#include<functional>
#include<chrono>
//#include<windows.h>
//#include<direct.h>
#include<random>
#include<sstream>

#define y0 asdahsdlkahsdad
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define taskname "sequence"
//#define GuiltiaSinJurai

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

template <typename T> inline void Cin(T &x)
{
    register char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar());
    for (x = 0; c >= '0' && c <= '9'; c = getchar())
        x = x * 10 + c - '0';
}

const int maxN = 1e5, maxK = 200;

int trace[maxN][maxK], s[maxN], nId, N, K, a, j;
static ll f[maxN];

struct TLine
{
    int x;
    ll y;
    inline TLine operator - (const TLine &l) const & { return {x - l.x, y - l.y}; }
    inline ll operator * (const TLine &l) const & { return x * l.y - y * l.x; }
} p[maxN];
int id[maxN];
inline bool Erase(int a, int b, int c)
{
    return (p[b] - p[a]) * (p[c] - p[a]) > 0;
}
#define Get(i) ((ll)p[i].x * t + p[i].y)

int main()
{
    #ifdef GuiltiaSinJurai
    auto start = chrono::steady_clock::now();
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);

    Cin(N); Cin(K);
    for (int i = 0; i < N; ++i)
    {
        Cin(a);
        if (i == 0) s[i] = a;
        else s[i] = s[i - 1] + a;
    }
    for (int k = 0; k < K; ++k)
    {
        nId = -1;
        j = 0;
        for (int i = k + 1, val = f[k]; i < N; ++i)
        {
            --i;
            p[i] = {s[i], val - (ll)s[i] * s[i]};
            while (nId >= 1 && Erase(id[nId - 1], id[nId], i)) --nId;
            id[++nId] = i;
            val = f[++i];
            int t = s[i];
            if (j > nId) j = min(j, nId);
            else while (j < nId && Get(id[j + 1]) > Get(id[j])) ++j;
            f[i] = Get(trace[i][k] = id[j]);
            //for (int j = 0; j <= nId; ++j) cout << id[j] << ' ';
            //cout << '\n';
            //cout << f[i] << ' ';
        }
        //cout << '\n';
    }
    cout << f[N - 1] << '\n';
    for (int i = N - 1; --K >= 0; )
    {
        cout << (i = trace[i][K]) + 1 << ' ';
    }

    #ifdef GuiltiaSinJurai
    auto end = chrono::steady_clock::now();
    cerr << "In milliseconds : "
         << chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << '\n' << "In seconds : "
         << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n';
    #endif
    return 0;

}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:98:36: warning: operation on 'trace[i][k]' may be undefined [-Wsequence-point]
             f[i] = Get(trace[i][k] = id[j]);
                        ~~~~~~~~~~~~^~~~~~~
sequence.cpp:65:23: note: in definition of macro 'Get'
 #define Get(i) ((ll)p[i].x * t + p[i].y)
                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...