Submission #360585

#TimeUsernameProblemLanguageResultExecution timeMemory
360585talant117408모임들 (IOI18_meetings)C++17
0 / 100
14 ms1388 KiB
#include "meetings.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define precision(n) fixed << setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define eps (double)1e-9 #define PI 2*acos(0.0) #define endl "\n" #define sz(v) int((v).size()) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define OK cout << "OK" << endl; vector<ll> minimum_costs(vector<int> h, vector<int> L, vector<int> R) { vector <ll> H; ll n = sz(h), q = sz(L); for(auto to : h) H.pb(to); if(q*n > 5000*5000) exit(0); vector <ll> ans; for(int i = 0; i < q; i++){ vector <ll> mx(n); ll sum = 0; int l = L[i], r = R[i]; stack <pii> st; for(int j = l; j <= r; j++){ ll cnt = 1; while(sz(st) && st.top().first <= H[j]){ cnt += st.top().second; sum -= st.top().first*st.top().second; st.pop(); } sum += H[j]*cnt; st.push(mp(H[j], cnt)); mx[j] += sum; } while(sz(st)) st.pop(); sum = 0; for(int j = r; j >= l; j--){ ll cnt = 1; while(sz(st) && st.top().first <= H[j]){ cnt += st.top().second; sum -= st.top().first*st.top().second; st.pop(); } sum += H[j]*cnt; st.push(mp(H[j], cnt)); mx[j] += sum; } ll res = 9e18; for(int j = l; j <= r; j++) res = min(res, mx[j]-H[j]); ans.pb(res); } 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...