#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<ll>;
using ll = long long;
using ii = pair<ll, ll>;
struct Dijkstra {
vector<vector<ii> > L;
ll n;
Dijkstra(ll N) : n(N), L(N) {}
void add_edge(ll u, ll v, ll w) {
L[u].push_back({v, w});
L[v].push_back({u, w});
}
ll dist(ll s, ll t) {
const ll INF = 1e18;
vector<ll> D(n, INF);
D[s] = 0;
priority_queue<pair<ll, ll> > PQ;
PQ.push({0, s});
while(!PQ.empty()) {
ll u = PQ.top().second;
ll d = - PQ.top().first;
PQ.pop();
if(D[u] != d) continue;
for(auto [it, w] : L[u]) {
if(D[it] > D[u] + w) {
D[it] = D[u] + w;
PQ.push({-D[it], it});
}
}
}
if(D[t] == INF) D[t] = -1;
return D[t];
}
};
long long min_distance(std::vector<int> x, std::vector<int> h, std::vector<int> l, std::vector<int> r, std::vector<int> y, int s, int g) {
ll n = x.size();
ll tmr = 0;
vector<vector<pair<ll, ll> > > Noduri(n); /// perechi(id, h)
vector<tuple<ll, ll, ll> > E;
for(ll i = 0; i < n; ++i) {
Noduri[i].push_back({tmr++, 0});
}
for(ll i = 0; i < l.size(); ++i) {
ll ult = -1;
for(ll j = l[i]; j <= r[i]; ++j) {
if(h[j] < y[i]) continue;
else {
Noduri[j].push_back({tmr++, y[i]});
if(ult != -1) {
E.emplace_back(tmr - 1, Noduri[ult].back().first, x[j] - x[ult]);
}
ult = j;
}
}
}
Dijkstra Sol(tmr);
for(auto [u, v, w] : E)
Sol.add_edge(u, v, w);
for(ll i = 0; i < n; ++i) {
sort(Noduri[i].begin(), Noduri[i].end(), [&](auto a, auto b) {return a.second < b.second;});
for(ll j = 0; j + 1 < Noduri[i].size(); ++j) {
Sol.add_edge(Noduri[i][j].first, Noduri[i][j + 1].first,
Noduri[i][j + 1].second - Noduri[i][j].second);
}
}
return Sol.dist(Noduri[s][0].first, Noduri[g][0].first);
}
Compilation message
walk.cpp:6:19: error: 'll' was not declared in this scope
6 | using vi = vector<ll>;
| ^~
walk.cpp:6:21: error: template argument 1 is invalid
6 | using vi = vector<ll>;
| ^
walk.cpp:6:21: error: template argument 2 is invalid
walk.cpp: In constructor 'Dijkstra::Dijkstra(ll)':
walk.cpp:12:8: warning: 'Dijkstra::n' will be initialized after [-Wreorder]
12 | ll n;
| ^
walk.cpp:11:25: warning: 'std::vector<std::vector<std::pair<long long int, long long int> > > Dijkstra::L' [-Wreorder]
11 | vector<vector<ii> > L;
| ^
walk.cpp:14:5: warning: when initialized here [-Wreorder]
14 | Dijkstra(ll N) : n(N), L(N) {}
| ^~~~~~~~
walk.cpp: In function 'long long int min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:52:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(ll i = 0; i < l.size(); ++i) {
| ~~^~~~~~~~~~
walk.cpp:73:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(ll j = 0; j + 1 < Noduri[i].size(); ++j) {
| ~~~~~~^~~~~~~~~~~~~~~~~~