#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0; i<n; ++i)
#define pb push_back
using ll = int64_t;
const ll inf = 4e18;
#define pi pair<ll,ll>
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define int ll
const int sz=1<<30;
struct sgt {
sgt *L, *R; int s;
sgt() {
L=R=NULL; s=inf;
}
void set(int l, int r, int i, int x) {
if (r-l==1) {
s=x; return;
}
int m=(l+r)>>1;
if (i<m) {
if (!L) L=new sgt();
L->set(l,m,i,x);
} else {
if (!R) R=new sgt();
R->set(m,r,i,x);
}
s = min(L?L->s:inf, R?R->s:inf);
}
void set(int i, int x) {
set(0,sz,i,x);
}
int query(int l, int r, int lx, int rx) {
if (rx<=l || r<=lx) return inf;
if (lx<=l && r<=rx) return s;
int m=(l+r)>>1;
int lq=L?L->query(l,m,lx,rx):inf;
int rq=R?R->query(m,r,lx,rx):inf;
return min(lq,rq);
}
int query(int l, int r) {
return query(0,sz,l,r);
}
};
#undef int
long long min_distance(vector<int>x, vector<int>h, vector<int>l, vector<int>r, vector<int>y, int s, int g) {
int n=x.size(), m=l.size();
#define int ll
sgt bottom, top;
bottom.set(0,0);
top.set(0,0);
vector<vector<int>> add(n), del(n);
del[0].pb(0);
add[n-1].pb(0);
forn(i,m) {
add[l[i]].pb(y[i]);
del[r[i]].pb(y[i]);
}
forn(i,n) {
vector<pi> toset;
for(auto&y:add[i]) {
int f = bottom.query(0,y+1);
int s = top.query(y,sz);
if (min(f,s)==inf) continue;
f+=y; s-=y;
int x=min(f,s);
toset.pb({y,x});
}
for(auto&y:del[i]) {
bottom.set(y,inf);
top.set(y,inf);
}
for(auto&x:toset) {
bottom.set(x.f,x.s-x.f);
top.set(x.f,x.s+x.f);
}
}
if (top.s==inf) return -1;
int f = top.s+x[n-1]-x[0];
return f;
#undef int
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
3676 KB |
Output is correct |
2 |
Correct |
370 ms |
94408 KB |
Output is correct |
3 |
Correct |
408 ms |
80716 KB |
Output is correct |
4 |
Correct |
429 ms |
99272 KB |
Output is correct |
5 |
Correct |
440 ms |
100100 KB |
Output is correct |
6 |
Correct |
451 ms |
102400 KB |
Output is correct |
7 |
Correct |
172 ms |
55828 KB |
Output is correct |
8 |
Correct |
312 ms |
94056 KB |
Output is correct |
9 |
Correct |
439 ms |
98368 KB |
Output is correct |
10 |
Correct |
130 ms |
19504 KB |
Output is correct |
11 |
Correct |
8 ms |
3392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
3676 KB |
Output is correct |
2 |
Correct |
370 ms |
94408 KB |
Output is correct |
3 |
Correct |
408 ms |
80716 KB |
Output is correct |
4 |
Correct |
429 ms |
99272 KB |
Output is correct |
5 |
Correct |
440 ms |
100100 KB |
Output is correct |
6 |
Correct |
451 ms |
102400 KB |
Output is correct |
7 |
Correct |
172 ms |
55828 KB |
Output is correct |
8 |
Correct |
312 ms |
94056 KB |
Output is correct |
9 |
Correct |
439 ms |
98368 KB |
Output is correct |
10 |
Correct |
130 ms |
19504 KB |
Output is correct |
11 |
Correct |
8 ms |
3392 KB |
Output is correct |
12 |
Correct |
375 ms |
88692 KB |
Output is correct |
13 |
Correct |
327 ms |
95820 KB |
Output is correct |
14 |
Correct |
426 ms |
94924 KB |
Output is correct |
15 |
Correct |
227 ms |
45772 KB |
Output is correct |
16 |
Correct |
233 ms |
44928 KB |
Output is correct |
17 |
Correct |
248 ms |
45068 KB |
Output is correct |
18 |
Correct |
228 ms |
45716 KB |
Output is correct |
19 |
Correct |
228 ms |
44968 KB |
Output is correct |
20 |
Correct |
203 ms |
55088 KB |
Output is correct |
21 |
Correct |
21 ms |
7880 KB |
Output is correct |
22 |
Correct |
248 ms |
74792 KB |
Output is correct |
23 |
Correct |
251 ms |
76192 KB |
Output is correct |
24 |
Correct |
272 ms |
82132 KB |
Output is correct |
25 |
Correct |
263 ms |
85996 KB |
Output is correct |
26 |
Correct |
270 ms |
94156 KB |
Output is correct |
27 |
Correct |
413 ms |
95608 KB |
Output is correct |
28 |
Correct |
315 ms |
99388 KB |
Output is correct |
29 |
Correct |
445 ms |
93860 KB |
Output is correct |
30 |
Correct |
174 ms |
55916 KB |
Output is correct |
31 |
Correct |
425 ms |
98444 KB |
Output is correct |
32 |
Correct |
120 ms |
15748 KB |
Output is correct |
33 |
Correct |
129 ms |
17228 KB |
Output is correct |
34 |
Correct |
134 ms |
23140 KB |
Output is correct |
35 |
Correct |
176 ms |
36172 KB |
Output is correct |
36 |
Correct |
168 ms |
32768 KB |
Output is correct |
37 |
Correct |
111 ms |
14796 KB |
Output is correct |
38 |
Correct |
121 ms |
18248 KB |
Output is correct |
39 |
Correct |
156 ms |
26340 KB |
Output is correct |
40 |
Correct |
124 ms |
18060 KB |
Output is correct |
41 |
Correct |
117 ms |
15820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |