#include "walk.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 1e5 + 10;
const long long inf = 1e18;
int n , m , a[N] , pos[N];
long long dis[N];
vector <int> comp , st[N] , fn[N];
struct bridge{
int l , r , y;
};
vector <bridge> vec;
bool cmp(bridge aa , bridge bb)
{
return aa.l < bb.l;
}
struct SEG{
long long mn[N << 2];
void Build(int node = 1 , int nl = 0 , int nr = m)
{
mn[node] = inf;
if(nr - nl == 1)
return;
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
Build(lc , nl , mid);
Build(rc , mid , nr);
}
void Set(int id , long long val , int node = 1 , int nl = 0 , int nr = m)
{
if(nr - nl == 1)
{
mn[node] = val;
return;
}
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
if(id < mid)
Set(id , val , lc , nl , mid);
else
Set(id , val , rc , mid , nr);
mn[node] = min(mn[lc] , mn[rc]);
}
long long Get(int l , int r , int node = 1 , int nl = 0 , int nr = m)
{
if(r <= nl || nr <= l)
return inf;
if(l <= nl && nr <= r)
return mn[node];
int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
return min(Get(l , r , lc , nl , mid) , Get(l , r , rc , mid , nr));
}
} seg[2];
long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int s, int g) {
n = x.size();
m = l.size();
for(int i = 0 ; i < n ; i++)
{
a[i] = h[i];
pos[i] = x[i];
}
for(int i = 0 ; i < m ; i++)
comp.push_back(y[i]);
seg[0].Build();
seg[1].Build();
sort(comp.begin() , comp.end());
comp.resize(unique(comp.begin() , comp.end()) - comp.begin());
for(int i = 0 ; i < m ; i++)
{
y[i] = lower_bound(comp.begin() , comp.end() , y[i]) - comp.begin();
st[l[i]].push_back(i);
fn[r[i]].push_back(i);
//cout << i << " : " << l[i] << " " << r[i] << " " << y[i] << " " << comp[y[i]] << endl;
}
for(auto u : st[0])
{
dis[u] = comp[y[u]];
seg[0].Set(y[u] , dis[u] - comp[y[u]]);
seg[1].Set(y[u] , dis[u] + comp[y[u]]);
//cout << u << " : " << dis[u] << endl;
}
for(int i = 1 ; i < n ; i++)
{
for(auto u : st[i])
{
//cout << u << " WTF " << seg[0].Get(0 , y[u]) << " " << seg[1].Get(y[u] , m) << endl;
dis[u] = min(seg[0].Get(0 , y[u]) + comp[y[u]] , seg[1].Get(y[u] , m) - comp[y[u]]);
}
for(auto u : fn[i])
{
seg[0].Set(y[u] , inf);
seg[1].Set(y[u] , inf);
}
for(auto u : st[i])
{
//cout << u << " : " << dis[u] << endl;
seg[0].Set(y[u] , dis[u] - comp[y[u]]);
seg[1].Set(y[u] , dis[u] + comp[y[u]]);
}
}
long long res = inf;
for(auto u : fn[n - 1])
res = min(res , dis[u] + comp[y[u]]);
res += (pos[n - 1] - pos[0]);
if(res >= inf)
res = -1;
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
10720 KB |
Output is correct |
2 |
Correct |
106 ms |
15640 KB |
Output is correct |
3 |
Correct |
114 ms |
16588 KB |
Output is correct |
4 |
Correct |
142 ms |
23060 KB |
Output is correct |
5 |
Correct |
138 ms |
21404 KB |
Output is correct |
6 |
Correct |
149 ms |
22736 KB |
Output is correct |
7 |
Correct |
81 ms |
17360 KB |
Output is correct |
8 |
Correct |
148 ms |
25396 KB |
Output is correct |
9 |
Correct |
139 ms |
24008 KB |
Output is correct |
10 |
Correct |
91 ms |
21920 KB |
Output is correct |
11 |
Correct |
9 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
10720 KB |
Output is correct |
2 |
Correct |
106 ms |
15640 KB |
Output is correct |
3 |
Correct |
114 ms |
16588 KB |
Output is correct |
4 |
Correct |
142 ms |
23060 KB |
Output is correct |
5 |
Correct |
138 ms |
21404 KB |
Output is correct |
6 |
Correct |
149 ms |
22736 KB |
Output is correct |
7 |
Correct |
81 ms |
17360 KB |
Output is correct |
8 |
Correct |
148 ms |
25396 KB |
Output is correct |
9 |
Correct |
139 ms |
24008 KB |
Output is correct |
10 |
Correct |
91 ms |
21920 KB |
Output is correct |
11 |
Correct |
9 ms |
7000 KB |
Output is correct |
12 |
Correct |
126 ms |
16592 KB |
Output is correct |
13 |
Correct |
138 ms |
22984 KB |
Output is correct |
14 |
Correct |
147 ms |
21440 KB |
Output is correct |
15 |
Correct |
102 ms |
22216 KB |
Output is correct |
16 |
Correct |
115 ms |
22216 KB |
Output is correct |
17 |
Correct |
124 ms |
22176 KB |
Output is correct |
18 |
Correct |
112 ms |
21964 KB |
Output is correct |
19 |
Correct |
96 ms |
22208 KB |
Output is correct |
20 |
Correct |
79 ms |
16844 KB |
Output is correct |
21 |
Correct |
20 ms |
9564 KB |
Output is correct |
22 |
Correct |
104 ms |
20640 KB |
Output is correct |
23 |
Correct |
109 ms |
21196 KB |
Output is correct |
24 |
Correct |
108 ms |
21452 KB |
Output is correct |
25 |
Correct |
118 ms |
21188 KB |
Output is correct |
26 |
Correct |
106 ms |
22216 KB |
Output is correct |
27 |
Correct |
143 ms |
21960 KB |
Output is correct |
28 |
Correct |
152 ms |
22984 KB |
Output is correct |
29 |
Correct |
140 ms |
22732 KB |
Output is correct |
30 |
Correct |
80 ms |
17020 KB |
Output is correct |
31 |
Correct |
139 ms |
23968 KB |
Output is correct |
32 |
Correct |
82 ms |
21964 KB |
Output is correct |
33 |
Correct |
84 ms |
23100 KB |
Output is correct |
34 |
Correct |
97 ms |
22476 KB |
Output is correct |
35 |
Correct |
93 ms |
22804 KB |
Output is correct |
36 |
Correct |
83 ms |
22760 KB |
Output is correct |
37 |
Correct |
79 ms |
21960 KB |
Output is correct |
38 |
Correct |
72 ms |
24472 KB |
Output is correct |
39 |
Correct |
113 ms |
22732 KB |
Output is correct |
40 |
Correct |
75 ms |
23496 KB |
Output is correct |
41 |
Correct |
76 ms |
22476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |