이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N;
int P[200005];
vector<int> ST[800005];
vector<int> adj[200005];
vector<int> H;
void build(int v, int l, int r) {
if(l == r) {
ST[v] = {P[l]};
return;
}
build(v * 2, l, (l + r) / 2);
build(v * 2 + 1, (l + r) / 2 + 1, r);
int i = 0, j = 0;
while(i < ST[v * 2].size() || j < ST[v * 2 + 1].size()) {
if(i == ST[v * 2].size())
ST[v].push_back(ST[v * 2 + 1][j++]);
else if(j == ST[v * 2 + 1].size())
ST[v].push_back(ST[v * 2][i++]);
else {
if(ST[v * 2][i] < ST[v * 2 + 1][j])
ST[v].push_back(ST[v * 2][i++]);
else ST[v].push_back(ST[v * 2 + 1][j++]);
}
}
}
int queryR(int v, int l, int r, int lo, int hi, int K) {
if(l > hi || r < lo) return 1e9 + 7;
if(l >= lo && r <= hi) {
int R = lower_bound(ST[v].begin(), ST[v].end(), K) - ST[v].begin();
if(R == ST[v].size()) return 1e9 + 7;
return ST[v][R];
}
return min(queryR(v * 2, l, (l + r) / 2, lo, hi, K),
queryR(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi, K));
}
int queryL(int v, int l, int r, int lo, int hi, int K) {
if(l > hi || r < lo) return -1;
if(l >= lo && r <= hi) {
int L = lower_bound(ST[v].begin(), ST[v].end(), K) - ST[v].begin();
if(L == 0) return -1;
return ST[v][--L];
}
return max(queryL(v * 2, l, (l + r) / 2, lo, hi, K),
queryL(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi, K));
}
void init(int _N, vector<int> _H) {
N = _N;
for(int l = 0; l < _N; l++) {
H.push_back(_H[l]);
P[_H[l]] = l;
}
build(1, 1, N);
for(int l = 0; l < _N; l++) {
int i = queryL(1, 1, N, 1, P[_H[l]] - 1, l);
int j = queryR(1, 1, N, P[_H[l]] + 1, N, l);
if(i != -1) adj[l].push_back(i);
if(j != 1e9 + 7) adj[l].push_back(j);
}
}
int minimum_jumps(int A, int B, int C, int D) {
vector<int> dis(N, 1e9 + 7); priority_queue<pair<int, int>> Q;
for(int l = A; l <= B; l++) {
dis[l] = 0; Q.push({0, l});
}
while(!Q.empty()) {
pair<int, int> U = Q.top(); Q.pop();
if(-U.first > dis[U.second]) continue;
if(U.second >= C && U.second <= D) return -U.first;
for(auto V : adj[U.second]) {
if(dis[U.second] + 1 < dis[V]) {
dis[V] = dis[U.second] + 1;
Q.push({-dis[V], V});
}
}
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'void build(int, int, int)':
jumps.cpp:19:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while(i < ST[v * 2].size() || j < ST[v * 2 + 1].size()) {
| ~~^~~~~~~~~~~~~~~~~~
jumps.cpp:19:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while(i < ST[v * 2].size() || j < ST[v * 2 + 1].size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:20:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if(i == ST[v * 2].size())
| ~~^~~~~~~~~~~~~~~~~~~
jumps.cpp:22:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | else if(j == ST[v * 2 + 1].size())
| ~~^~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp: In function 'int queryR(int, int, int, int, int, int)':
jumps.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(R == ST[v].size()) return 1e9 + 7;
| ~~^~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |