#include "walk.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define iter(a) a.begin(), a.end()
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
#define lsort(a) sort(iter(a))
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MAX = 1LL << 60;
struct SegmentTree{
vector<ll> st;
void resize(int n){
st.resize(4 * n, MAX);
}
void modify(int pos, ll v, int L, int R, int id){
if(L == R){
st[id] = v;
return;
}
int M = (L + R) / 2;
if(pos <= M) modify(pos, v, L, M, 2 * id + 1);
else modify(pos, v, M + 1, R, 2 * id + 2);
st[id] = min(st[2 * id + 1], st[2 * id + 2]);
}
ll query(int l, int r, int L, int R, int id){
if(l == L && r == R){
return st[id];
}
int M = (L + R) / 2;
if(r <= M) return query(l, r, L, M, 2 * id + 1);
else if(l > M) return query(l, r, M + 1, R, 2 * id + 2);
else return min(query(l, M, L, M, 2 * id + 1), query(M + 1, r, M + 1, R, 2 * id + 2));
}
};
int n, m;
vector<int> x, h, tl, tr, ty;
int sv, gv;
SegmentTree pre, suf;
vector<int> discr;
int sz;
int dcr(int v){
return lower_bound(iter(discr), v) - discr.begin();
}
ll calc(int y){
return min(discr[y] + pre.query(0, y, 0, sz - 1, 0), -discr[y] + suf.query(y, sz - 1, 0, sz - 1, 0));
}
ll min_distance(vector<int> _x, vector<int> _h, vector<int> _l, vector<int> _r, vector<int> _y, int _s, int _g){
x = _x; h = _h; tl = _l; tr = _r; ty = _y; sv = _s; gv = _g;
n = x.size();
m = ty.size();
assert(sv == 0 && gv == n - 1);
discr = ty;
discr.eb(0);
lsort(discr);
discr.resize(unique(iter(discr)) - discr.begin());
sz = discr.size();
pre.resize(sz);
suf.resize(sz);
vector<vector<int>> add(n), del(n);
for(int i = 0; i < m; i++){
add[tl[i]].eb(dcr(ty[i]));
del[tr[i]].eb(dcr(ty[i]));
}
del[0].eb(0);
pre.modify(0, 0, 0, sz - 1, 0);
suf.modify(0, 0, 0, sz - 1, 0);
vector<bool> use(sz);
for(int i = 0; i < n - 1; i++){
for(int j : add[i]){
use[j] = true;
ll v = calc(j);
if(v == MAX) continue;
//cerr << "test " << i << " " << discr[j] << " " << v << "\n";
pre.modify(j, v - discr[j], 0, sz - 1, 0);
suf.modify(j, v + discr[j], 0, sz - 1, 0);
}
for(int j : del[i]){
if(use[j]) continue;
pre.modify(j, MAX, 0, sz - 1, 0);
suf.modify(j, MAX, 0, sz - 1, 0);
}
for(int j : add[i]) use[j] = false;
//cerr << "test " << i << " ";
/*for(int j = 0; j < sz; j++){
cerr << pre.query(j, j, 0, sz - 1, 0) + discr[j] << " ";
}*/
//cerr << "\n";
}
ll v = calc(0);
if(v == MAX) return -1;
return v + x[n - 1] - x[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3964 KB |
Output is correct |
2 |
Correct |
176 ms |
11708 KB |
Output is correct |
3 |
Correct |
191 ms |
14780 KB |
Output is correct |
4 |
Correct |
287 ms |
25528 KB |
Output is correct |
5 |
Correct |
319 ms |
24084 KB |
Output is correct |
6 |
Correct |
300 ms |
25380 KB |
Output is correct |
7 |
Correct |
165 ms |
18300 KB |
Output is correct |
8 |
Correct |
312 ms |
27816 KB |
Output is correct |
9 |
Correct |
273 ms |
26508 KB |
Output is correct |
10 |
Correct |
173 ms |
21304 KB |
Output is correct |
11 |
Correct |
15 ms |
4540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3964 KB |
Output is correct |
2 |
Correct |
176 ms |
11708 KB |
Output is correct |
3 |
Correct |
191 ms |
14780 KB |
Output is correct |
4 |
Correct |
287 ms |
25528 KB |
Output is correct |
5 |
Correct |
319 ms |
24084 KB |
Output is correct |
6 |
Correct |
300 ms |
25380 KB |
Output is correct |
7 |
Correct |
165 ms |
18300 KB |
Output is correct |
8 |
Correct |
312 ms |
27816 KB |
Output is correct |
9 |
Correct |
273 ms |
26508 KB |
Output is correct |
10 |
Correct |
173 ms |
21304 KB |
Output is correct |
11 |
Correct |
15 ms |
4540 KB |
Output is correct |
12 |
Correct |
185 ms |
14876 KB |
Output is correct |
13 |
Correct |
295 ms |
25484 KB |
Output is correct |
14 |
Correct |
255 ms |
24096 KB |
Output is correct |
15 |
Correct |
171 ms |
20512 KB |
Output is correct |
16 |
Correct |
167 ms |
20632 KB |
Output is correct |
17 |
Correct |
198 ms |
20628 KB |
Output is correct |
18 |
Correct |
187 ms |
20404 KB |
Output is correct |
19 |
Correct |
181 ms |
20636 KB |
Output is correct |
20 |
Correct |
146 ms |
18284 KB |
Output is correct |
21 |
Correct |
32 ms |
9412 KB |
Output is correct |
22 |
Correct |
198 ms |
21304 KB |
Output is correct |
23 |
Correct |
214 ms |
21736 KB |
Output is correct |
24 |
Correct |
243 ms |
22640 KB |
Output is correct |
25 |
Correct |
241 ms |
22644 KB |
Output is correct |
26 |
Correct |
226 ms |
24000 KB |
Output is correct |
27 |
Correct |
239 ms |
24532 KB |
Output is correct |
28 |
Correct |
292 ms |
25448 KB |
Output is correct |
29 |
Correct |
242 ms |
25312 KB |
Output is correct |
30 |
Correct |
166 ms |
18276 KB |
Output is correct |
31 |
Correct |
315 ms |
26556 KB |
Output is correct |
32 |
Correct |
158 ms |
19164 KB |
Output is correct |
33 |
Correct |
177 ms |
21024 KB |
Output is correct |
34 |
Correct |
179 ms |
21376 KB |
Output is correct |
35 |
Correct |
180 ms |
20600 KB |
Output is correct |
36 |
Correct |
181 ms |
19700 KB |
Output is correct |
37 |
Correct |
126 ms |
16956 KB |
Output is correct |
38 |
Correct |
121 ms |
20668 KB |
Output is correct |
39 |
Correct |
160 ms |
22172 KB |
Output is correct |
40 |
Correct |
147 ms |
19684 KB |
Output is correct |
41 |
Correct |
109 ms |
17860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |