이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
//#define int long long
using namespace std;
#include "meetings.h"
const long long inf = 1e17;
vector<vector<int> > mx;
int M, K;
int query(int l, int r){
int ind = 0;
while((1 << (ind + 1)) <= (r - l + 1)){
ind++;
}
return max(mx[l][ind], mx[r - (1 << ind) + 1][ind]);
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int n = H.size();
vector<array<int, 3> > segments;
int cnt = 0;
for(int i = 0; i < n; i++){
if(i == n-1 || H[i] == 2){
if(H[i] == 1){
segments.pb({i - cnt, i, cnt + 1});
}
else if(cnt > 0){
segments.pb({i - cnt, i - 1, cnt});
}
cnt = 0;
}
else cnt++;
}
M = segments.size();
K = 18;
if(M > 0){
mx.resize(M);
for(int i = 0; i < M; i++){
mx[i].resize(K);
mx[i][0] = segments[i][2];
}
for(int i = 1; i < K; i++){
for(int j = 0; j < M; j++){
mx[j][i] = max(mx[j][i-1], mx[min(M-1, j + (1 << (i - 1)))][i-1]);
}
}
}
int Q = L.size();
vector<long long> C(Q);
for (int j = 0; j < Q; ++j) {
long long ans = 2 * (R[j] - L[j] + 1);
if(M > 0){
int l = 0, r = M-1;
while(l < r){
int m = (l + r)/2;
if(segments[m][1] >= L[j]) r = m;
else l = m + 1;
}
int sol = l;
l = 0, r = M-1;
while(l < r){
int m = (l + r + 1)/2;
if(segments[m][0] <= R[j]) l = m;
else r = m - 1;
}
int sag = l;
int cik = 0;
if(segments[sol][0] < L[j]){
cik = max(cik, segments[sol][1] - L[j] + 1);
sol++;
}
if(segments[sag][1] > R[j]){
cik = max(cik, R[j] - segments[sag][0] + 1);
sag--;
}
if(sol <= sag){
cik = max(cik, query(sol, sag));
}
ans -= cik;
}
C[j] = ans;
}
return C;
}
# | 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... |