Language: C++

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string>
using namespace std;

int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}

int max(int a, int b) {
	if (a > b)
		return a;
	return b;
}
int min(int a, int b) {
	if (a < b)
		return a;
	return b;
}

struct tree {
	int v;
	tree *l, *r,*p;
};

int main() {
	ios_base::sync_with_stdio(false);
	int a, b, q, buf, sl=-1, sr=-1, tl=-1, tr=-1, x; cin >> a >> b >> q;
	tree *s = NULL, *t = NULL, *p = NULL;
	for (int i = 0; i < a; i++) {
		cin >> buf;
		if (s == NULL) {
			s = (tree*)malloc(sizeof(tree));
			s->v = buf;
			s->p = NULL;
			s->l = NULL;
			s->r = NULL;
			continue;
		}
		p = s;
		while (true) {
			if (p->v < buf) {
				if (p->r) {
					p = p->r;
					continue;
				}
				p->r = (tree*)malloc(sizeof(tree));
				p->r->v = buf;
				p->r->p = p;
				p->p = NULL;
				p->l = NULL;
				p->r = NULL;
				break;
			}
			if (p->l) {
				p = p->l;
				continue;
			}
			p->l = (tree*)malloc(sizeof(tree));
			p->l->v = buf;
			p->l->p = p;
			p->p = NULL;
			p->l = NULL;
			p->r = NULL;
			break;
		}
	}
	for (int i = 0; i < b; i++) {
		cin >> buf;
		if (t == NULL) {
			t = (tree*)malloc(sizeof(tree));
			t->v = buf;
			t->p = NULL;
			t->l = NULL;
			t->r = NULL;
			continue;
		}
		p = t;
		while (true) {
			if (p->v < buf) {
				if (p->r) {
					p = p->r;
					continue;
				}
				p->r = (tree*)malloc(sizeof(tree));
				p->r->v = buf;
				p->p = NULL;
				p->l = NULL;
				p->r = NULL;
				break;
			}
			if (p->l) {
				p = p->l;
				continue;
			}
			p->l = (tree*)malloc(sizeof(tree));
			p->l->v = buf;
			p->p = NULL;
			p->l = NULL;
			p->r = NULL;
			break;
		}
	}
	for (int i = 0; i < q; i++) {
		cin >> x;
		sl = -1;
		sr = -1;
		tl = -1;
		tr = -1;
		p = s;
		while (true) {
			if (p->v < x) {
				if (!p->r) {
					sl = p->v;
					while (p->p) {
						if (p->p->l == p) {
							sr = p->p->v;
							break;
						}
						p = p->p;
					}
					break;
				}
				p = p->r;
				continue;
			}
			if (!p->l) {
				sr = p->v;
				while (p->p) {
					if (p->p->r == p) {
						sl = p->p->v;
						break;
					}
					p = p->p;
				}
				break;
			}
			p = p->l;
		}
		p = t;
		while (true) {
			if (p->v < x) {
				if (!p->r) {
					tl = p->v;
					while (p->p) {
						if (p->p->l == p) {
							tr = p->p->v;
							break;
						}
						p = p->p;
					}
					break;
				}
				p = p->r;
				continue;
			}
			if (!p->l) {
				tr = p->v;
				while (p->p) {
					if (p->p->r == p) {
						tl = p->p->v;
						break;
					}
					p = p->p;
				}
				break;
			}
			p = p->l;
		}
		if (sl == -1) {
			if (tl == -1) {
				cout << max(sr, tr)-x << endl;
				continue;
			}
			if (tr == -1) {
				cout << min(x - tl, sr - x) + sr - tl << endl;
				continue;
			}
			cout << min(max(sr, tr) - x, min(x - tl, sr - x) + sr - tl);
		}
		else if (sr == -1) {
			if (tr == -1) {
				cout << x-min(sl, tl) << endl;
				continue;
			}
			if (tl == -1) {
				cout << min(x - tr, sl - x) + tr - sl << endl;
				continue;
			}
			cout << min(x - min(sl, tl), min(tr - x, x - sl) + tr - sl);
		}
		else if (tl == -1) {
			cout << min(max(sr, tr) - x, min(x - sl, tr - x) + tr - sl);
		}
		else if(tr==-1)
			cout << min(x - min(sl, tl), min(sr - x, x - tl) + sr - tl);
		else cout << min(min(x-min(sl, tl), max(sr, tr)-x)) << endl;
	}
	
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:198:33: error: no matching function for call to 'min(int)'
  198 |                 else cout << min(min(x-min(sl, tl), max(sr, tr)-x)) << endl;
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
a.cc:16:5: note: candidate: 'int min(int, int)'
   16 | int min(int a, int b) {
      |     ^~~
a.cc:16:5: note:   candidate expects 2 arguments, 1 provided