#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=1e5+99;
const ll inf=1e16;
int n,m;
ll dist[N],pos[N],seg[2][N<<2];
vector<int> ad[N],dl[N];
vector<pair<int,int>> vec;
void change(int x,ll val,int s){
x+=m;
seg[s][x]=val;
for(;x>1;x>>=1){
seg[s][x>>1]=min(seg[s][x],seg[s][x^1]);
}
}
ll get(int l,int r,int s){
ll ans=inf;
for(l+=m,r+=m;l<r;l>>=1,r>>=1){
if(l&1){
minm(ans,seg[s][l++]);
}
if(r&1){
minm(ans,seg[s][--r]);
}
}
return ans;
}
ll min_distance(vector<int> a,vector<int> h,vector<int> l,vector<int> r,vector<int> y,int s,int g) {
n=a.size();
y.pb(0);
l.pb(n-1);
r.pb(n-1);
m=l.size();
f(i,0,m){
ad[l[i]].pb(i);
dl[r[i]].pb(i);
vec.pb({y[i],i});
}
sort(all(vec));
f(i,0,int(vec.size())) pos[vec[i].S]=i;
f(s,0,2) f(i,0,N<<2) seg[s][i]=inf;
f(i,0,n){
for(auto x : ad[i]){
dist[x]=min(y[x]+get(0,pos[x],0),get(pos[x],m,1)-y[x]);
if(l[x]==0) dist[x]=y[x];
//cout<<x<<" -> "<<dist[x]<<endl;
change(pos[x],dist[x]-y[x],0);
change(pos[x],dist[x]+y[x],1);
}
for(auto x : dl[i]){
change(pos[x],inf,0);
change(pos[x],inf,1);
}
}
if(dist[m-1]>=inf){
return -1;
}
else{
return a[n-1]-a[0]+dist[m-1];
}
}
/*
5 3
0 6
4 6
5 6
6 6
9 6
3 4 1
1 3 3
0 2 6
0 4
0, 4, 5, 6, 9],
[6, 6, 6, 6, 6],
[3, 1, 0],
[4, 3, 2],
[1, 3, 6],
0, 4)
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
15416 KB |
Output is correct |
2 |
Correct |
116 ms |
18908 KB |
Output is correct |
3 |
Correct |
105 ms |
19728 KB |
Output is correct |
4 |
Correct |
171 ms |
25536 KB |
Output is correct |
5 |
Correct |
183 ms |
24000 KB |
Output is correct |
6 |
Correct |
157 ms |
25368 KB |
Output is correct |
7 |
Correct |
87 ms |
21104 KB |
Output is correct |
8 |
Correct |
181 ms |
27836 KB |
Output is correct |
9 |
Correct |
162 ms |
26504 KB |
Output is correct |
10 |
Correct |
125 ms |
24520 KB |
Output is correct |
11 |
Correct |
15 ms |
12832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
15416 KB |
Output is correct |
2 |
Correct |
116 ms |
18908 KB |
Output is correct |
3 |
Correct |
105 ms |
19728 KB |
Output is correct |
4 |
Correct |
171 ms |
25536 KB |
Output is correct |
5 |
Correct |
183 ms |
24000 KB |
Output is correct |
6 |
Correct |
157 ms |
25368 KB |
Output is correct |
7 |
Correct |
87 ms |
21104 KB |
Output is correct |
8 |
Correct |
181 ms |
27836 KB |
Output is correct |
9 |
Correct |
162 ms |
26504 KB |
Output is correct |
10 |
Correct |
125 ms |
24520 KB |
Output is correct |
11 |
Correct |
15 ms |
12832 KB |
Output is correct |
12 |
Correct |
119 ms |
19856 KB |
Output is correct |
13 |
Correct |
189 ms |
25476 KB |
Output is correct |
14 |
Correct |
149 ms |
23944 KB |
Output is correct |
15 |
Correct |
164 ms |
24628 KB |
Output is correct |
16 |
Correct |
180 ms |
24832 KB |
Output is correct |
17 |
Correct |
161 ms |
24836 KB |
Output is correct |
18 |
Correct |
155 ms |
24708 KB |
Output is correct |
19 |
Correct |
155 ms |
24824 KB |
Output is correct |
20 |
Correct |
94 ms |
20940 KB |
Output is correct |
21 |
Correct |
39 ms |
14852 KB |
Output is correct |
22 |
Correct |
128 ms |
23012 KB |
Output is correct |
23 |
Correct |
118 ms |
23492 KB |
Output is correct |
24 |
Correct |
128 ms |
23896 KB |
Output is correct |
25 |
Correct |
133 ms |
23420 KB |
Output is correct |
26 |
Correct |
118 ms |
24488 KB |
Output is correct |
27 |
Correct |
162 ms |
24440 KB |
Output is correct |
28 |
Correct |
186 ms |
25416 KB |
Output is correct |
29 |
Correct |
225 ms |
25224 KB |
Output is correct |
30 |
Correct |
80 ms |
20976 KB |
Output is correct |
31 |
Correct |
183 ms |
26348 KB |
Output is correct |
32 |
Correct |
126 ms |
24436 KB |
Output is correct |
33 |
Correct |
183 ms |
25732 KB |
Output is correct |
34 |
Correct |
110 ms |
24908 KB |
Output is correct |
35 |
Correct |
149 ms |
25428 KB |
Output is correct |
36 |
Correct |
136 ms |
25276 KB |
Output is correct |
37 |
Correct |
140 ms |
24616 KB |
Output is correct |
38 |
Correct |
144 ms |
26888 KB |
Output is correct |
39 |
Correct |
118 ms |
25264 KB |
Output is correct |
40 |
Correct |
124 ms |
26068 KB |
Output is correct |
41 |
Correct |
140 ms |
24904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
11220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |