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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETLL(x) scanf("%lld", &x)
#define GETSTR(x) scanf("%s", x)

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

struct ie_t
{
	ll pos;
	char dir;
};

int main()
{
	int ie_num, hito_num;
	ll time;
	vector<ie_t> ie;
	vi hito;
	GETINT(ie_num);
	GETLL(time);
	GETINT(hito_num);
	ie.reserve(ie_num);
	hito.reserve(hito_num);
	RE(i, ie_num)
	{
		ll pos;
		int dir;
		GETLL(pos);
		GETINT(dir);
		ie_t temp;
		temp.pos = pos;
		switch (dir)
		{
		case 1:
			temp.dir = 1;
			break;
		case 2:
			temp.dir = -1;
			break;
		}
		ie.push_back(temp);
	}
	RE(i, hito_num)
	{
		int temp;
		GETINT(temp);
		hito.push_back(temp - 1);
	}
	vector<ll> result;
	RE(hito_cur, hito_num)
	{
		int hito_ieidx = hito[hito_cur];
		ie_t hito_ie = ie[hito_ieidx];
		if ((hito_ieidx >= ie_num - 1 && hito_ie.dir == 1) ||
			(hito_ieidx <= 0 && hito_ie.dir == -1))
		{
			result.push_back(hito_ie.pos + hito_ie.dir * time);
			continue;
		}
		int hito_n_ieidx = hito_ieidx + hito_ie.dir;
		ie_t hito_n_ie = ie[hito_n_ieidx];
		bool fin = false;
		while (hito_ie.dir == hito_n_ie.dir)
		{
			if ((hito_n_ieidx >= ie_num - 1 && hito_ie.dir == 1) ||
				(hito_n_ieidx <= 0 && hito_ie.dir == -1))
			{
				result.push_back(hito_ie.pos + hito_ie.dir * time);
				fin = true;
				break;
			}
			if (hito_ie.pos - hito_n_ie.pos >= time &&
				hito_n_ie.pos - hito_ie.pos >= time)
			{
				result.push_back(hito_ie.pos + hito_ie.dir * time);
				fin = true;
				break;
			}
			hito_n_ieidx += hito_ie.dir;
			hito_n_ie = ie[hito_n_ieidx];
		}
		if (fin)
		{
			continue;
		}
		ie_t hito_nprev_ie = ie[hito_n_ieidx - hito_ie.dir];
		ll len = (hito_n_ie.pos + hito_nprev_ie.pos) / 2 - hito_ie.pos;
		if (len * hito_ie.dir > time)
		{
			len = time * hito_ie.dir;
		}
		result.push_back(len + hito_ie.pos);
	}
	RE(i, hito_num)
	{
		printf("%lld\n", result[i]);
	}
	return 0;
}