Submission #1053299

# Submission time Handle Problem Language Result Execution time Memory
1053299 2024-08-11T10:22:29 Z Tob Sky Walking (IOI19_walk) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

#include "walk.h"

#define F first
#define S second
#define pb push_back

#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

const int N = 1e5 + 7, C = 12e5 + 7;
const ll inf = 1e18;

int n, m, cnt;
ll g[N], h[N], dis[C];
vector <int> ad[N];
vector <pii> adj[C];

void Edge(int x, int y, int val) {
	adj[x].pb({y, val});
	adj[y].pb({x, val});
}

ll E(ll x, ll y) {return (x << 32)+y;}

ll min_distance(vi x, vi h, vi l, vi r, vi y, int sta, int en) {
	n = x.size(); m = l.size();
	map <int, vector <int> > ma;
	unordered_map <ll, int> wh;
	for (int i = 0; i < n; i++) ma[h[i]].pb(i);
	for (int i = 0; i < m; i++) ma[y[i]].pb(i+n);
	set <int> st;
	cnt = n;
	while (!ma.empty()) {
		auto it = *(--ma.end());
		for (auto xx : it.S) {
			if (xx < n) st.insert(xx);
			else {
				xx -= n;
				auto p = st.lower_bound(l[xx]);
				int la = -1;
				while (p != st.end() && *p <= r[xx]) {
					ad[*p].pb(it.F);
					int tmp = wh[E(*p, it.F)];
					if (!tmp) {
						tmp = cnt;
						wh[E(*p, it.F)] = cnt++;
					}
					if (la != -1) Edge(wh[E(la, it.F)], tmp, x[*p]-x[la]);
					la = *p;
					++p;
				}
			}
		}
		ma.erase(--ma.end());
	}
	for (int i = 0; i < n; i++) {
		sort(all(ad[i]));
		if (ad[i].empty()) continue;
		Edge(i, wh[E(i, ad[i][0])], ad[i][0]);
		for (int j = 1; j < ad[i].size(); j++) Edge(wh[E(i, ad[i][j-1])], wh[E(i, ad[i][j])], ad[i][j]-ad[i][j-1]);
	}
	
	
	set <pii> s;
	s.insert({0, sta});
	for (int i = 0; i < cnt; i++) dis[i] = inf;
	dis[sta] = 0;
	
	while (!s.empty()) {
		auto p = s.begin();
		int xx = p -> S;
		s.erase(p);
		for (auto y : adj[xx]) {
			if (dis[xx] + y.S < dis[y.F]) {
				if (dis[y.F] != inf) s.erase({dis[y.F], y.F});
				dis[y.F] = dis[xx] + y.S;
				s.insert({dis[y.F], y.F});
			}
		}
	}
	
	return (dis[en] >= inf) ? -1 : dis[en];
}

int main() {
	int n, m;
	assert(2 == scanf("%d%d", &n, &m));
	vector<int> x(n), h(n);
	for (int i = 0; i < n; i++)
		assert(2 == scanf("%d%d", &x[i], &h[i]));
	vector<int> l(m), r(m), y(m);
	for (int i = 0; i < m; i++)
		assert(3 == scanf("%d%d%d", &l[i], &r[i], &y[i]));
	int s, g;
	assert(2 == scanf("%d%d", &s, &g));
	fclose(stdin);

	long long result = min_distance(x, h, l, r, y, s, g);

	printf("%lld\n", result);
	fclose(stdout);
	return 0;
}

Compilation message

walk.cpp: In function 'll min_distance(vi, vi, vi, vi, vi, int, int)':
walk.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for (int j = 1; j < ad[i].size(); j++) Edge(wh[E(i, ad[i][j-1])], wh[E(i, ad[i][j])], ad[i][j]-ad[i][j-1]);
      |                   ~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cc3IOh4e.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccAa0XCg.o:walk.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status