Language: C++

// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using IP = pair<int, P>;
using LLP = pair<ll, LP>;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

// template specialization of std::hash for std::pair
namespace std {
template<typename T, typename U>
struct hash<pair<T, U> > {
    size_t operator()(const pair<T, U> &key) const noexcept {
        size_t h1 = hash<T>()(key.first);
        size_t h2 = hash<U>()(key.second);
        return h1 ^ (h2 << 1);
    }
};
} // namespace std

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    size_t sz = v.size();
    os << "[";
    for (size_t i = 0; i < sz-1; i++) {
        os << v[i] << ", ";
    }
    os << v[sz-1] <<  "]";
    return os;
}

template<typename T>
void printArray(T *arr, size_t sz) {
    cerr << "[";
    for (size_t i = 0; i < sz-1; i++) {
        cerr << arr[i] << ",";
    }
    cerr << arr[sz-1] <<  "]" << endl;
}

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

struct Compare {
    //vector<ll> &x_, &y_;
    //Compare(vector<ll> &x, vector<ll> &y): x_(x), y_(y) {}
    //bool operator()(const P &lhs, const P &rhs) {
    //    return x_[lhs.fi]+y_[lhs.se] < x_[rhs.fi]+y_[rhs.se];
    //}
    bool operator()(const int x, const int y) {
        return x < y;
    }
};

// print floating-point number
// cout << fixed << setprecision(12) <<

// }}}

int A, B, Q;
ll s[100010], t[100010], x[100010];
ll sm[100010], tm[100010];

unordered_map<ll, int> m;
unordered_map<ll, LP> mxs, mxt, mst, mts;

void solve()
{
    sort(sm, sm+A);
    sort(tm, tm+B);
    REP (i, A) {
        ll j = lower_bound(t, t+B, s[i]) - t;
        auto kit = lower_bound(tm, tm+B, -s[i]);
        ll k = m[-*kit];
        ll dj = abs(t[j]-s[i]);
        ll dk = abs(t[k]-s[i]);
        if (dj < dk) {
            mst[s[i]] = mp(dj, j);
        } else {
            mst[s[i]] = mp(dk, k);
        }
    }
    REP (i, B) {
        ll j = lower_bound(s, s+A, t[i]) - s;
        auto kit = lower_bound(sm, sm+B, -t[i]);
        ll k = m[-*kit];
        ll dj = abs(s[j]-t[i]);
        ll dk = abs(s[k]-t[i]);
        if (dj < dk) {
            mts[t[i]] = mp(dj, j);
        } else {
            mts[t[i]] = mp(dk, k);
        }
    }
    REP (i, Q) {
        {
            ll j = lower_bound(s, s+A, x[i]) - s;
            auto kit = lower_bound(sm, sm+A, -x[i]);
            ll k = m[-*kit];
            ll dj = abs(s[j]-x[i]);
            ll dk = abs(s[k]-x[i]);
            if (dj < dk) {
                mxs[x[i]] = mp(dj, j);
            } else {
                mxs[x[i]] = mp(dk, k);
            }
        }
        {
            ll j = lower_bound(t, t+B, x[i]) - t;
            auto kit = lower_bound(tm, tm+B, -x[i]);
            ll k = m[-*kit];
            ll dj = abs(t[j]-x[i]);
            ll dk = abs(t[k]-x[i]);
            if (dj < dk) {
                mxt[x[i]] = mp(dj, j);
            } else {
                mxt[x[i]] = mp(dk, k);
            }
        }
        ll dxs = mxs[x[i]].fi + mst[s[mxs[x[i]].se]].fi;
        ll dxt = mxt[x[i]].fi + mts[t[mxt[x[i]].se]].fi;
        cout << min(dxs, dxt) << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A >> B >> Q;
    REP (i, A) {
        cin >> s[i];
        m[s[i]] = i;
        sm[i] = -s[i];
    }
    REP (i, B) {
        cin >> t[i];
        m[t[i]] = i;
        tm[i] = -t[i];
    }
    REP (i, Q) {
        cin >> x[i];
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Compiler output:
a.cc: In function 'void solve()':
a.cc:114:10: error: reference to 'tm' is ambiguous
  114 |     sort(tm, tm+B);
      |          ^~
In file included from /usr/include/time.h:39,
                 from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc:114:14: error: reference to 'tm' is ambiguous
  114 |     sort(tm, tm+B);
      |              ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc:117:32: error: reference to 'tm' is ambiguous
  117 |         auto kit = lower_bound(tm, tm+B, -s[i]);
      |                                ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc:117:36: error: reference to 'tm' is ambiguous
  117 |         auto kit = lower_bound(tm, tm+B, -s[i]);
      |                                    ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc:154:36: error: reference to 'tm' is ambiguous
  154 |             auto kit = lower_bound(tm, tm+B, -x[i]);
      |                                    ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc:154:40: error: reference to 'tm' is ambiguous
  154 |             auto kit = lower_bound(tm, tm+B, -x[i]);
      |                                        ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~
a.cc: In function 'int main()':
a.cc:183:9: error: reference to 'tm' is ambiguous
  183 |         tm[i] = -t[i];
      |         ^~
/usr/include/x86_64-linux-gnu/bits/types/struct_tm.h:7:8: note: candidates are: 'struct tm'
    7 | struct tm
      |        ^~
a.cc:106:16: note:                 'll tm [100010]'
  106 | ll sm[100010], tm[100010];
      |                ^~