제출 #851041

#제출 시각아이디문제언어결과실행 시간메모리
851041no_wayBigger segments (IZhO19_segments)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define no_way                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
typedef vector<int> vi;

template <class T>
bool ckmin(T &a, const T &b)
{
    return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve(int test)
{
    int n;
    cin >> n;
    vi arr(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        if (i)
            arr[i] += arr[i - 1];
    }
    vi dp(n + 1), prev(n + 1);
    for (int i = 1; i <= n; i++)
    {
        prev[i] = max(prev[i], prev[i - 1]);
        dp[i] = dp[prev[i]] + 1;
        int l = i, r = n, ans = n;
        while (l <= r)
        {
            int mid = (l + r) >> 1;
            if (arr[mid] - arr[i] >= arr[i] - arr[prev[i]])
                r = mid - 1, ans = mid;
            else
                l = mid + 1;
        }
        prev[ans] = i;
    }
    cout << dp[n] << endl;
    return;
}

signed main()
{
    no_way;
    //    #ifndef ONLINE_JUDGE
    //       freopen("input.txt", "r", stdin);
    //       freopen("output.txt", "w", stdout);
    //    #endif
    clock_t z = clock();
    int tests = 1;
    // cin >> tests;
    while (tests--)
    {
        solve(tests);
    }
    cerr << "Run Time: " << ((double)(clock() - z) / CLOCKS_PER_SEC);
    return 0;
}
#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...