제출 #502951

#제출 시각아이디문제언어결과실행 시간메모리
502951Vladth11Bigger segments (IZhO19_segments)C++14
100 / 100
137 ms29852 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast", "unroll-loops")

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 500001;
const ll VMAX = 21;
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;

ll s[NMAX];
ll v[NMAX];
pii dp[NMAX];

priority_queue <pii> pq;
priority_queue <pii> stergem;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i;
    cin >> n;
    for(i = 1; i <= n; i++)
        cin >> v[i];
    for(i = 1; i <= n; i++)
        s[i] = s[i - 1] + v[i];
    pq.push({0, 0});
    ll offset = 0;
    for(i = 1; i <= n; i++){
        offset += v[i];
        while(stergem.size() && -stergem.top().first - offset <= 0){
            pq.push({dp[stergem.top().second].first, stergem.top().second});
            stergem.pop();
        }
        dp[i] = {pq.top().first + 1, s[i] - s[pq.top().second]};
        stergem.push({-(dp[i].second + offset), i}); /// am uitat de offset :( si apoi totul cu minus
    }
    cout << dp[n].first;
    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...