Submission #313127

#TimeUsernameProblemLanguageResultExecution timeMemory
313127reymontada61Meetings (IOI18_meetings)C++14
19 / 100
5598 ms6648 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; vector<int> h; vector<long long> cost; void addcosts(int from, int to, int update) { long long adder = 0; vector<pair<long long, int>> proc; proc.push_back({INT_MAX, from-update}); for (int j=from; (from<=j && j<=to) || (to <= j && j <= from); j+=update) { while (proc.back().first <= h[j]) { long long t = proc.size(); long long co = abs(proc[t-1].second - proc[t-2].second) * proc[t-1].first; adder -= co; proc.pop_back(); } proc.push_back({h[j], j}); long long t = proc.size(); long long co = abs(proc[t-1].second - proc[t-2].second) * proc[t-1].first; adder += co; cost[j] += adder; } } std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) { int Q = L.size(); std::vector<long long> C(Q); int n = H.size(); h = H; cost.resize(n, 0); for (int i=0; i<Q; i++) { int l = L[i], r = R[i]; for (int j=l; j<=r; j++) { cost[j] = 0; } addcosts(l, r, 1); addcosts(r, l, -1); for (int i=l; i<=r; i++) { cost[i] -= H[i]; } C[i] = LLONG_MAX; for (int j=l; j<=r; j++) { C[i] = min(C[i], cost[j]); } } return C; }
#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...