Language: C++

#include<bits/stdc++.h>

using namespace std;

#define ll long long

int binary_search(ll x, int left, int right, vector<ll> &u){
  int center = left + (right - left) / 2;
  if(right - left <= 1 || u[center] == x) return center;
  else if(u[center] < x) return binary_search(x, center, right, u);
  else return binary_search(x, left, center, u);
}

ll min(ll a, ll b){
  if(a > b) return b;
  else return a;
}

ll abs(ll a){
  if(a < 0) return -a;
  else return a;
}

int main(){
  int a, b;
  int q;
  cin >> a >> b >> q;
  vector<ll> s(a + 2);
  vector<ll> t(b + 2);
  for(int i = 1; i <= a; i++) cin >> s[i];
  for(int i = 1; i <= b; i++) cin >> t[i];
  s[0] = -20000000000;
  t[0] = -20000000000;
  s[a + 1] = 30000000000;
  t[b + 1] = 30000000000;
  for(int i = 0; i < q; i++){
    ll x; cin >> x;
    int xa = binary_search(x, 0, a + 2, s);
    int xb = binary_search(x, 0, b + 2, t);
    ll min1 = min(abs(x - s[xa]) + abs(s[xa] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa]));
    ll min2 = min(abs(x - s[xa]) + abs(s[xa] - t[xb + 1]), abs(x - t[xb + 1]) + abs(t[xb + 1] - s[xa]));
    ll min3 = min(abs(x - s[xa + 1]) + abs(s[xa + 1] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa + 1]));
    ll min4 = min(abs(x - s[xa + 1]) + abs(s[xa + 1] - t[xb + 1]), abs(x - s[xa + 1]) + abs(s[xa + 1] - t[xb + 1]));
    cout << min(min(min1, min2), min(min3, min4)) << endl;
    //cout << s[xa] << " " << x << " " << s[xa + 1] << endl;
    //cout << t[xb] << " " << x << " " << t[xb + 1] << endl;
    //cout <<min1 << " " << min2 << " " << min3 << " " << min4 << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:22: error: call of overloaded 'abs(long long int)' is ambiguous
   40 |     ll min1 = min(abs(x - s[xa]) + abs(s[xa] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa]));
      |                   ~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:40:39: error: call of overloaded 'abs(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)' is ambiguous
   40 |     ll min1 = min(abs(x - s[xa]) + abs(s[xa] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa]));
      |                                    ~~~^~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:40:59: error: call of overloaded 'abs(long long int)' is ambiguous
   40 |     ll min1 = min(abs(x - s[xa]) + abs(s[xa] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa]));
      |                                                        ~~~^~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:40:76: error: call of overloaded 'abs(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)' is ambiguous
   40 |     ll min1 = min(abs(x - s[xa]) + abs(s[xa] - t[xb]), abs(x - t[xb]) + abs(t[xb] - s[xa]));
      |                                                                         ~~~^~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:41:22: error: call of overloaded 'abs(long long int)' is ambiguous
   41 |     ll min2 = min(abs(x - s[xa]) + abs(s[xa] - t[xb + 1]), abs(x - t[xb + 1]) + abs(t[xb + 1] - s[xa]));
      |                   ~~~^~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:41:39: error: call of overloaded 'abs(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)' is ambiguous
   41 |     ll min2 = min(abs(x - s[xa]) + abs(s[xa] - t[xb + 1]), abs(x - t[xb + 1]) + abs(t[xb + 1] - s[xa]));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
a.cc:19:4: note: candidate: 'long long int abs(long long int)'
   19 | ll abs(ll a){
      |    ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:41:63: error: call of overloaded 'abs(long long int)' is ambiguous
   41 |     ll min2 = min(abs(x - s[xa]) + abs(s[xa] - t[xb + 1]), abs(x - t[xb + 1]) + abs(t[xb + 1] - s[xa]));
      |                                                            ~~~^~~~~~~~~~~~~~~
/usr/i