Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	args := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(args[0])
	t, _ := strconv.ParseInt(args[1], 10, 64)

	q, _ := strconv.Atoi(args[2])

	pos := make([]int64, n)
	direction := make([]bool, n)

	for i := 0; i < n; i++ {
		sc.Scan()
		args = strings.Split(sc.Text(), " ")

		pos[i], _ = strconv.ParseInt(args[0], 10, 64)
		q, _ := strconv.Atoi(args[1])
		if q == 1 {
			direction[i] = true
		}
	}

	qq := make([]int, q)
	for i := 0; i < q; i++ {
		sc.Scan()
		args = strings.Split(sc.Text(), " ")

		qq[i], _ = strconv.Atoi(args[0])
	}

	ans(n, q, t, pos, direction, qq)

}

func ans(n, q int, t int64, pos []int64, dir []bool, qq []int) {

	colleation := []int64{} // syoutotu positon

	for i := 1; i < n; i++ {
		if dir[i-1] == dir[i] {
			continue
		}
		colleation = append(colleation, (pos[i-1]+pos[i])/2)

	}
	//fmt.Println(colleation)
	for i := 0; i < q; i++ {
		var ans int64
		ans = int64(-9999999)
		if dir[qq[i]-1] == true {
			// 東向きなら現ポジから＋方向で一番近い衝突点との距離を求めて、Tとの差が
			for _, v := range colleation {
				if v <= pos[qq[i]-1] {
					continue
				} else {
					// 衝突予定点が確定。衝突点との距離がT以下なら衝突点で停止
					if v-pos[qq[i]-1] <= t {
						ans = v
					} else {
						ans = pos[qq[i]-1] + int64(t)
					}
					break
				}
			}
			if ans == -9999999 {
				ans = pos[qq[i]-1] + int64((t))
			}

		} else {
			// nishi向きなら現ポジから-方向で一番近い衝突点との距離を求めて、Tとの差が
			for j := len(colleation); j > 0; j-- {
				if colleation[j-1] >= pos[qq[i]-1] {
					continue
				}
				v := colleation[j-1]
				//fmt.Printf("hoge=%d\n", v)
				// 衝突予定点が確定
				if pos[qq[i]-1]-v <= t {
					ans = v
				} else {
					ans = pos[qq[i]-1] - int64((t))
				}
				break

			}
			if ans == -9999999 {
				ans = pos[qq[i]-1] - int64((t))
			}

		}
		fmt.Printf("%d\n", ans)

	}

}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(asd, fgh) for(ll asd = 0; asd < fgh; asd++)

struct P{
  ll pos;
  ll dir;
  bool stopped;
};


int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N, T, Q; cin >> N >> T >> Q;
  vector<P> p(N);

  REP(i, N){
    ll a, d;
    cin >> a >> d;
    p[i].pos = a;
    if(d == 1){
      p[i].dir = 1;
    }else{
      p[i].dir = -1;
    }
    p[i].stopped = false;
  }

  for(ll i = 0; i < N-1; i++){
    if(p[i].dir == 1 && p[i+1].dir == -1){
      if((p[i+1].pos - p[i].pos) / 2 <= T){
        p[i+1].pos = p[i].pos = (p[i+1].pos + p[i].pos)/2;
      }else{
        p[i+1].pos -= T;
        p[i].pos += T;
      }
      p[i+1].stopped = p[i].stopped = true;
    }
  }

  for(ll i = 0; i < N; i++){
    if(p[i].stopped) continue;

    if(p[i].dir == 1){
      bool flg = false;
      for(ll j = i+1; j < N; j++){
        if(p[j].pos - p[i].pos > T){
          p[i].pos += T;
          flg = true;
          break;
        }else if(p[j].stopped == true){
          p[i].pos = p[j].pos;
          flg = true;
          break;
        }
      }
      if(!flg){
        p[i].pos += T;
      }

    } else {
      bool flg = false;
      for(ll j = i-1; j >= 0; j--){
        if(p[i].pos - p[j].pos > T){
          p[i].pos -= T;
          flg = true;
          break;
        }else if(p[j].stopped == true){
          p[i].pos = p[j].pos;
          flg = true;
          break;
        }
      }
      if(!flg){
        p[i].pos -= T;
      }
    }
  }

  REP(i, Q){
    int q; cin >> q; q--;
    cout << p[q].pos << endl;
  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

const int INF = 1ll << 60;

int A[100000];
int D[100000];
int stops[100000];

signed main() {
	int N, T, Q;
	cin >> N >> T >> Q;
	rep(i, N) cin >> A[i] >> D[i];

	rep(i, N) {
		stops[i] = (D[i] == 1 ? 1 : -1) * (1ll << 60);
	}

	rep(i, 1, N) if (D[i - 1] == 1 && D[i] == 2) {
		int s = stops[i] = stops[i - 1] = (A[i] + A[i - 1]) / 2;
		for (int j = i - 1; j >= 0 && D[j] == 1; j--) {
			stops[j] = s;
		}
		while (i + 1 < N && D[i + 1] == 2) {
			stops[i + 1] = s;
			i++;
		}
	}

	rep(i, Q) {
		int x;
		cin >> x;
		x--;
		int ans;
		if (D[x] == 1) ans = min(A[x] + T, stops[x]);
		else ans = max(A[x] - T, stops[x]);
		cout << ans << endl;
	}
	//system("pause");
}

C++: #include <stdio.h>
#include <algorithm>

long long int N, T, Q;
long long int A[112345], D[112345];
long long int X[1123];
long long int t[112345];

int main(void) {
	scanf("%lld%lld%lld", &N, &T, &Q);
	for (long long int i = 0; i < N; ++i) { scanf("%lld%lld", &A[i], &D[i]); }
	for (long long int i = 0; i < Q; ++i) { scanf("%lld", &X[i]); }

	for (long long int i = 0; i < N - 1; ++i) {
		if (D[i] == 1 && D[i + 1] == 2) {
			long long int t_mem = (A[i] + A[i + 1]) / 2;
			t[i] = t_mem;
			t[i + 1] = t_mem;
			for (long long int j = i - 1; j >= 0; --j) {
				if (D[j] == 1) {
					t[j] = t_mem;
				}
				else { break; }
			}
			for (long long int j = i + 1; j < N; ++j) {
				if (D[j] == 2) {
					t[j] = t_mem;
				}
				else { break; }
			}
		}
	}

	for (long long int i = 0; i < N; ++i) {
		if(T<std::llabs(A[i]-t[i])){
			if (D[i] == 1) {
				t[i] = A[i] + T;
			}
			if (D[i] == 2) {
				t[i] = A[i] - T;
			}
		}
	}

	for (long long int i = 0; i < Q; ++i) {
		printf("%lld\n", t[X[i] - 1]);
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>

using namespace std;

long long int A[200000], D[200000];

int main(){
	
	long long int N, T, Q;
	
	cin >> N >> T >> Q;
	
	long long int const LL_MAX = 1000000000000000001;
	long long int east = LL_MAX;
	
	vector<long long int> v;
	
	for(int i = 0; i < N; i++){
		cin >> A[i] >> D[i];
		if(D[i] == 1){
			east = A[i];
		}else{
			if(east == LL_MAX){
				continue;
			}
			v.push_back((east + A[i]) / 2);
			east = LL_MAX;
		}
	}
	/*
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
	*/
	for(int i = 0; i < Q; i++){
		int num;
		cin >> num;
		num--;
		int index = distance(v.begin(), lower_bound(v.begin(), v.end(), A[num]));
		if(D[num] == 2){
			index--;
		}
		//cout << index << " ";
		if(index < 0 || index >= v.size()){
			if(D[num] == 1){
				cout << A[num] + T << endl;
			}else{
				cout << A[num] - T << endl;
			}
		}else{
			if(D[num] == 1){
				cout << min(A[num] + T, v[index]) << endl;
			}else{
				cout << max(A[num] - T, v[index]) << endl;
			}
		}
	}
	
	return 0;
}