This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<long long> minimum_costs(vector<signed> H, vector<signed> L,
vector<signed> R) {
int N = H.size(), Q = L.size();
stack<int> stk;
vector<int> f2s(N, 0), b2s(N, 0);
for (int i = 0; i < N; i++)
{
if (H[i] == 2)
{
f2s[i] = i;
while (!stk.empty())
{
f2s[stk.top()] = i;
stk.pop();
}
}
else
{
stk.push(i);
}
}
while (!stk.empty())
{
f2s[stk.top()] = -1;
stk.pop();
}
for (int i = N - 1; i >= 0; i--)
{
if (H[i] == 2)
{
b2s[i] = i;
while (!stk.empty())
{
b2s[stk.top()] = i;
stk.pop();
}
}
else
{
stk.push(i);
}
}
while (!stk.empty())
{
b2s[stk.top()] = -1;
stk.pop();
}
vector<int> ans;
for (int i = 0; i < Q; i++)
{
if (f2s[L[i]] == -1 || f2s[L[i]] > R[i])
ans.push_back(R[i] + 1 - L[i]);
else
ans.push_back((R[i] + 1 - L[i]) * 2 - max(f2s[L[i]] - L[i], R[i] - b2s[R[i]]));
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |