Language: C++

#include <algorithm>
#include <climits>
#include <iostream>

long long ntemples, nshrines, nquestions;
std::vector<long long> shrines;
std::vector<long long> temples;
std::vector<long long> questions;

long long smaller_eq_point(long long target, const std::vector<long long>& v)
{
  long long ok = 0;
  long long ng = (long long)v.size();
  while (1 < abs(ok - ng)) {
    long long mid = (ok + ng) / 2;
    if (v.at(mid) <= target) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return v.at(ok);
}

long long larger_eq_point(long long target, const std::vector<long long>& v)
{
  long long ok = (long long)v.size()-1;
  long long ng = -1;
  while (1 < abs(ok - ng)) {
    long long mid = (ok + ng) / 2;
    if (target <= v.at(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return v.at(ok);
}

long long solve(long long start)
{
  long long left_shrine = smaller_eq_point(start, shrines);
  long long left_temple = smaller_eq_point(start, temples);
  long long right_shrine = larger_eq_point(start, shrines);
  long long right_temple = larger_eq_point(start, temples);
  long long result = LLONG_MAX;

  /*
  std::cout << '\n';
  std::cout << left_shrine << '\n';
  std::cout << left_temple << '\n';
  std::cout << right_shrine << '\n';
  std::cout << right_temple << '\n';
  */

  if (left_shrine <= start && left_temple <= start) {
    result = std::min(result, std::max(start-left_shrine, start-left_temple));
  }
  if (left_shrine <= start && start <= right_temple) {
    result = std::min(result,
        std::min((start-left_shrine)*2+(right_temple-start),
                 (start-left_shrine)  +(right_temple-start)*2));
  }
  if (start <= right_shrine && left_temple <= start) {
    result = std::min(result,
        std::min((right_shrine-start)*2+(start-left_temple),
                 (right_shrine-start)  +(start-left_temple)*2));
  }
  if (start <= right_shrine && start <= right_temple) {
    result = std::min(result, std::max(right_shrine-start, right_temple-start));
  }
  return result;
}

int main()
{
  std::cin >> nshrines >> ntemples >> nquestions;
  for (long long i = 0; i < nshrines; i++) {
    long long tmp;
    std::cin >> tmp;
    shrines.push_back(tmp);
  }
  for (long long i = 0; i < ntemples; i++) {
    long long tmp;
    std::cin >> tmp;
    temples.push_back(tmp);
  }
  for (long long i = 0; i < nquestions; i++) {
    long long tmp;
    std::cin >> tmp;
    questions.push_back(tmp);
  }
  std::sort(shrines.begin(), shrines.end());
  std::sort(temples.begin(), temples.end());
  for (long long i = 0; i < nquestions; i++) {
    std::cout << solve(questions.at(i)) << '\n';
  }
  return 0;
}


Compiler output:
a.cc:6:6: error: 'vector' in namespace 'std' does not name a template type
    6 | std::vector<long long> shrines;
      |      ^~~~~~
a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    3 | #include <iostream>
  +++ |+#include <vector>
    4 | 
a.cc:7:6: error: 'vector' in namespace 'std' does not name a template type
    7 | std::vector<long long> temples;
      |      ^~~~~~
a.cc:7:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    7 | std::vector<long long> temples;
      | ^~~
a.cc:8:6: error: 'vector' in namespace 'std' does not name a template type
    8 | std::vector<long long> questions;
      |      ^~~~~~
a.cc:8:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    8 | std::vector<long long> questions;
      | ^~~
a.cc:10:57: error: 'vector' in namespace 'std' does not name a template type
   10 | long long smaller_eq_point(long long target, const std::vector<long long>& v)
      |                                                         ^~~~~~
a.cc:10:52: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   10 | long long smaller_eq_point(long long target, const std::vector<long long>& v)
      |                                                    ^~~
a.cc:10:63: error: expected ',' or '...' before '<' token
   10 | long long smaller_eq_point(long long target, const std::vector<long long>& v)
      |                                                               ^
a.cc: In function 'long long int smaller_eq_point(long long int, int)':
a.cc:13:29: error: 'v' was not declared in this scope
   13 |   long long ng = (long long)v.size();
      |                             ^
a.cc: At global scope:
a.cc:25:56: error: 'vector' in namespace 'std' does not name a template type
   25 | long long larger_eq_point(long long target, const std::vector<long long>& v)
      |                                                        ^~~~~~
a.cc:25:51: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   25 | long long larger_eq_point(long long target, const std::vector<long long>& v)
      |                                                   ^~~
a.cc:25:62: error: expected ',' or '...' before '<' token
   25 | long long larger_eq_point(long long target, const std::vector<long long>& v)
      |                                                              ^
a.cc: In function 'long long int larger_eq_point(long long int, int)':
a.cc:27:29: error: 'v' was not declared in this scope
   27 |   long long ok = (long long)v.size()-1;
      |                             ^
a.cc: In function 'long long int solve(long long int)':
a.cc:42:51: error: 'shrines' was not declared in this scope; did you mean 'nshrines'?
   42 |   long long left_shrine = smaller_eq_point(start, shrines);
      |                                                   ^~~~~~~
      |                                                   nshrines
a.cc:43:51: error: 'temples' was not declared in this scope; did you mean 'ntemples'?
   43 |   long long left_temple = smaller_eq_point(start, temples);
      |                                                   ^~~~~~~
      |                                                   ntemples
a.cc: In function 'int main()':
a.cc:81:5: error: 'shrines' was not declared in this scope; did you mean 'nshrines'?
   81 |     shrines.push_back(tmp);
      |     ^~~~~~~
      |     nshrines
a.cc:86:5: error: 'temples' was not declared in this scope; did you mean 'ntemples'?
   86 |     temples.push_back(tmp);
      |     ^~~~~~~
      |     ntemples
a.cc:91:5: error: 'questions' was not declared in this scope; did you mean 'nquestions'?
   91 |     questions.push_back(tmp);
      |     ^~~~~~~~~
      |     nquestions
a.cc:93:13: error: 'shrines' was not declared in this scope; did you mean 'nshrines'?
   93 |   std::sort(shrines.begin(), shrines.end());
      |             ^~~~~~~
      |             nshrines
a.cc:94:13: error: 'temples' was not declared in this scope; did you mean 'ntemples'?
   94 |   std::sort(temples.begin(), temples.end());
      |             ^~~~~~~
      |             ntemples
a.cc:96:24: error: 'questions' was not declared in this scope; did you mean 'nquestions'?
   96 |     std::cout << solve(questions.at(i)) << '\n';
      |                        ^~~~~~~~~
      |                        nquestions