이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int n;
vector<int> h, adj[200005];
struct segTree {
int seg[800005][2];
void build(int i, int l, int r, int type) {
if(l==r) {
if(type==1) {
seg[i][0] = 2e9;
seg[i][1] = -2e9;
} else {
seg[i][0] = seg[i][1] = h[l];
}
return;
}
int m = (l+r)/2;
build(i*2+1, l, m, type);
build(i*2+2, m+1, r, type);
seg[i][0] = min(seg[i*2+1][0], seg[i*2+2][0]);
seg[i][1] = max(seg[i*2+1][1], seg[i*2+2][1]);
}
void update(int i, int l, int r, int x, int val) {
if(l==r) {
seg[i][0] = seg[i][1] = val;
return;
}
int m = (l+r)/2;
if(x<=m) update(i*2+1, l, m, x, val);
else update(i*2+2, m+1, r, x, val);
seg[i][0] = min(seg[i*2+1][0], seg[i*2+2][0]);
seg[i][1] = max(seg[i*2+1][1], seg[i*2+2][1]);
}
int query(int i, int l, int r, int wl, int wr, int j) {
if(wl<=l && wr>=r) return seg[i][j];
if(wl>r || wr<l) return (j==0 ? 2e9 : -2e9);
int m = (l+r)/2;
return (j==0 ? min(query(i*2+1, l, m, wl, wr, j), query(i*2+2, m+1, r, wl, wr, j)) : max(query(i*2+1, l, m, wl, wr, j), query(i*2+2, m+1, r, wl, wr, j)));
}
int queryh(int i, int l, int r, int wl, int wr, int bound) {
if(wl>r || wr<l || seg[i][0]>bound) return -2e9;
if(wl<=l && wr>=r && seg[i][1]<bound) return seg[i][1];
int m = (l+r)/2;
return max(queryh(i*2+1, l, m, wl, wr, bound), queryh(i*2+2, m+1, r, wl, wr, bound));
}
}posi, hi;
int tol[200005], tor[200005][20], diss[200005];
void dfs(int u, int dis) {
diss[u] = dis;
for(int v:adj[u]) dfs(v, dis+1);
}
vector<pii> v;
void init(int N, std::vector<int> H) {
n = N;
h = H;
for(int i=0;i<n;i++) v.push_back({h[i], i});
sort(v.begin(), v.end());
posi.build(0, 0, n-1, 1);
for(int i=n-1;i>=0;i--) {
int x = posi.query(0, 0, n-1, 0, v[i].second-1, 1);
if(x>-2e9) adj[v[i].second].push_back(x);
x = posi.query(0, 0, n-1, v[i].second+1, n-1, 0);
if(x<2e9) adj[v[i].second].push_back(x);
posi.update(0, 0, n-1, v[i].second, v[i].second);
}
hi.build(0, 0, n-1, 2);
}
int minimum_jumps(int A, int B, int C, int D) {
A = hi.queryh(0, 0, n-1, A, B, h[C]);
if(A==-2e9) return -1;
A = v[A-1].second;
vector<int> mindis(n, 2e9);
priority_queue<pii, vector<pii>, greater<pii>> pq;
mindis[A] = 0;
pq.push({0, A});
while(!pq.empty()) {
auto [dis, u] = pq.top();
pq.pop();
if(mindis[u]!=dis) continue;
if(u>=C && u<=D) return dis;
for(int v:adj[u]) {
if(h[v]<=h[C] && mindis[v]>dis+1) {
mindis[v] = dis+1;
pq.push({dis+1, v});
}
}
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:89:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | auto [dis, u] = pq.top();
| ^
# | 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... |