Language: C++

#include <bits/stdc++.h>
using namespace std;
long long saitankyori(vector<int> &x, long long key) { //配列xの中で最もkeyに近いものについて、keyとの差を返す
    auto a = lower_bound(x.begin(), x.end(), key);
    int k = a - x.begin();
    if(k==0) return abs(key - x.at(k));
    if(k==x.size()) return abs(key - x.at(k-1));
    else return min(abs(key - x.at(k)), abs(key - x.at(k-1)));
}
int saitan_i(vector<int> &x, int key) { //配列xの中で最もkeyに近いもののindexを返す
    auto a = lower_bound(x.begin(), x.end(), key);
    int k = a - x.begin();
    if(k==0) return k;
    if(k==x.size()) return k-1;
    else if(abs(key - x.at(k)) <= abs(key - x.at(k-1))) return k;
    else return k-1;
}

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A), t(B), x(Q);
    for(int i = 0; i < A; i++) cin >> s.at(i);
    for(int i = 0; i < B; i++) cin >> t.at(i);
    for(int i = 0; i < Q; i++) cin >> x.at(i);
    sort(s.begin(), s.end());
    
    vector<int> s_saitan(A), t_saitan(B);
    for(int i = 0; i < A; i++) {
        s_saitan.at(i) = saitankyori(t, s.at(i));
    }
    for(int i = 0; i < B; i++) {
        t_saitan.at(i) = saitankyori(s, t.at(i));
    }
    
    for(int i = 0; i < Q; i++) {
        //寺->神社の場合
        long long ans1 = saitankyori(t, x.at(i)) + t_saitan.at(saitan_i(t, x.at(i)));
        //神社->寺の場合
        long long ans2 = saitankyori(s, x.at(i)) + s_saitan.at(saitan_i(s, x.at(i)));
        //小さい方を出力
        cout << min(ans1, ans2) << endl;
    }
    
}


Compiler output:
a.cc: In function 'int main()':
a.cc:30:38: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   30 |         s_saitan.at(i) = saitankyori(t, s.at(i));
      |                                      ^
a.cc:3:36: note: in passing argument 1 of 'long long int saitankyori(std::vector<int>&, long long int)'
    3 | long long saitankyori(vector<int> &x, long long key) { //配列xの中で最もkeyに近いものについて、keyとの差を返す
      |                       ~~~~~~~~~~~~~^
a.cc:33:38: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   33 |         t_saitan.at(i) = saitankyori(s, t.at(i));
      |                                      ^
a.cc:3:36: note: in passing argument 1 of 'long long int saitankyori(std::vector<int>&, long long int)'
    3 | long long saitankyori(vector<int> &x, long long key) { //配列xの中で最もkeyに近いものについて、keyとの差を返す
      |                       ~~~~~~~~~~~~~^
a.cc:38:38: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   38 |         long long ans1 = saitankyori(t, x.at(i)) + t_saitan.at(saitan_i(t, x.at(i)));
      |                                      ^
a.cc:3:36: note: in passing argument 1 of 'long long int saitankyori(std::vector<int>&, long long int)'
    3 | long long saitankyori(vector<int> &x, long long key) { //配列xの中で最もkeyに近いものについて、keyとの差を返す
      |                       ~~~~~~~~~~~~~^
a.cc:38:73: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   38 |         long long ans1 = saitankyori(t, x.at(i)) + t_saitan.at(saitan_i(t, x.at(i)));
      |                                                                         ^
a.cc:10:27: note: in passing argument 1 of 'int saitan_i(std::vector<int>&, int)'
   10 | int saitan_i(vector<int> &x, int key) { //配列xの中で最もkeyに近いもののindexを返す
      |              ~~~~~~~~~~~~~^
a.cc:40:38: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   40 |         long long ans2 = saitankyori(s, x.at(i)) + s_saitan.at(saitan_i(s, x.at(i)));
      |                                      ^
a.cc:3:36: note: in passing argument 1 of 'long long int saitankyori(std::vector<int>&, long long int)'
    3 | long long saitankyori(vector<int> &x, long long key) { //配列xの中で最もkeyに近いものについて、keyとの差を返す
      |                       ~~~~~~~~~~~~~^
a.cc:40:73: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::vector<long long int>'
   40 |         long long ans2 = saitankyori(s, x.at(i)) + s_saitan.at(saitan_i(s, x.at(i)));
      |                                                                         ^
a.cc:10:27: note: in passing argument 1 of 'int saitan_i(std::vector<int>&, int)'
   10 | int saitan_i(vector<int> &x, int key) { //配列xの中で最もkeyに近いもののindexを返す
      |              ~~~~~~~~~~~~~^