Submission #571096

#TimeUsernameProblemLanguageResultExecution timeMemory
571096elazarkorenMeetings (IOI18_meetings)C++17
19 / 100
5548 ms6204 KiB
#include "meetings.h"
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const ll infinity = 1e18;

vi minimum_costs(vector<int> h, vector<int> L, vector<int> R) {
    int q = L.size(), n = h.size();
    vi ans(q);
    for (int j = 0; j < q; j++) {
        int l = L[j], r = R[j];
        vi cost(n);
        stack<int> stk;
        stk.push(l);
        ll curr = h[l];
        for (int i = l + 1; i <= r; i++) {
            while (!stk.empty() && h[stk.top()] <= h[i]) {
                int b = stk.top();
                stk.pop();
                int a = stk.empty() ? l - 1 : stk.top();
                curr -= ll(b - a) * h[b];
            }
            int a = stk.empty() ? l - 1 : stk.top();
            stk.push(i);
            curr += ll(i - a) * h[i];
            cost[i] = curr - h[i];
        }
        while (!stk.empty()) stk.pop();
        stk.push(r);
        curr = h[r];
        for (int i = r - 1; i >= l; i--) {
            while (!stk.empty() && h[stk.top()] <= h[i]) {
                int b = stk.top();
                stk.pop();
                int a = stk.empty() ? r + 1 : stk.top();
                curr -= ll(a - b) * h[b];
            }
            int a = stk.empty() ? r + 1 : stk.top();
            stk.push(i);
            curr += ll(a - i) * h[i];
            cost[i] += curr - h[i];
        }
        ans[j] = infinity;
        for (int i = l; i <= r; i++) {
            chkmin(ans[j], cost[i] + h[i]);
        }
    }
    return ans;
}
#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...