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"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

struct group { LL begin, end, pos; };

LL N, T, Q, A[112345], D[112345], X[1123];
std::vector<group>list;

int main()
{
	in >> N >> T >> Q;
	rep(i, N) { in >> A[i] >> D[i]; }
	rep(i, Q) { in >> X[i]; }

	rep(i, N)
	{
		if (D[i] == 1)
		{
			LL p;
			bool eastFlag = true, meetFlag = true;
			for (LL j = i; j < N; ++j)
			{
				if (eastFlag)
				{
					if (D[j] == 2)
					{
						if (A[j] - A[j - 1] <= T * 2) { p = (A[j] + A[j - 1]) / 2; }
						else { meetFlag = false; }
						eastFlag = false;
					}
				}
				else
				{
					if (D[j] == 1)
					{
						if (meetFlag) { list.push_back({ i,j - 1,p }); }
						i = j - 1;
						break;
					}
					if (j == N - 1)
					{
						if (meetFlag) { list.push_back({ i,j,p }); }
						i = j;
						break;
					}
				}
			}
		}
	}
	int seek = 0;
	rep(i, N)
	{
		if (seek < (int)list.size())
		{
			if (list[seek].begin <= i && i <= list[seek].end)
			{
				if (abs(A[i] - list[seek].pos) <= T) { A[i] = list[seek].pos; }
				else { A[i] += (D[i] == 1 ? T : -T); }
			}
			else if (list[seek].end < i) { ++seek; --i; }
			else { A[i] += (D[i] == 1 ? T : -T); }
		}
		else { A[i] += (D[i] == 1 ? T : -T); }
	}

	rep(i, Q) { out << A[X[i] - 1] << std::endl; }
	return 0;
}

C++: #include<bits/stdc++.h>
#define INF 100010001000
using namespace std;
long long int p[100010],ans[100010],dire[100010],n,t,q,x[100010],mm,s1;


int main(){

    for(int i=0;i<100010;i++)ans[i]=INF;
    mm=INF;
    cin >> n >> t >> q;
    for(int i=1;i<=n;i++)cin >> x[i] >> dire[i];

    for(int i=1;i<=n;i++){
        if(dire[i]==1&&dire[i+1]==2){
            mm=(x[i]+x[i+1])/2;
            ans[i]=mm,ans[i+1]=mm;

            for(int j=i-1;j>0;j--){
                if(dire[j]==1)ans[j]=mm;
                else break;
            }
        }else if(dire[i]==2)ans[i]=mm;
    }

    for(int i=0;i<q;i++){
        cin >> mm;
        s1=x[mm]-ans[mm];
        if(s1<0)s1=-s1;
        //cout << "??????????????? " << x[mm] << "  ?????????????????? "  << x[mm]-t << "  ??¶????????£?????´??? " << ans[mm] << endl;
        if(t<s1){
            if(dire[mm]==1)cout << x[mm]+t << endl;
            else cout << x[mm]-t << endl;
        }else cout << ans[mm] << endl;
    }

return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define INF 3000000000000000000
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n-1);i>=0;i--)
using namespace std;


 long long int x[200000][3]={0};//0:x 1:direction
 long long int p[2000];
 long long int ans[2000];

 long long int n,t,q;

int main(){
	scanf("%d%d%d",&n,&t,&q);
	REP(i,n)scanf("%d %d",&x[i][0],&x[i][1]);
	REP(i,q)scanf("%d",&p[i]);
	//search opposite people//calc
	bool flag=false;
	REP(i,n-1){
		if(x[i][1]==1&&x[i+1][1]==2){x[i+1][2]=(x[i+1][0]+x[i][0])/2;x[i][2]=x[i+1][2];}
		if(x[i][1]==2&&x[i+1][1]==2){x[i+1][2]=x[i][2];}
	}
	if(x[n-1][1]==1)x[n-1][2]=INF;
	RREP(i,n){
		if(x[i][1]==1&&x[i-1][1]==1){x[i-1][2]=x[i][2];}
	}
	if(x[0][1]==2)x[0][2]=INF;
	 long long int c;
	//judge
	REP(i,q){
	c=x[p[i]-1][0]-t*(x[p[i]-1][1]*2-3);
	if((x[p[i]-1][1]==1&&c>x[p[i]-1][2])||(x[p[i]-1][1]==2&&c<x[p[i]-1][2]))printf("%d\n",x[p[i]-1][2]);
	else printf("%d\n",c);
	}
	//REP(i,n){REP(j,3)printf("%d ",x[i][j]);printf("\n ");}
	return ;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int main() {
	LL n, t, q;
	cin >> n >> t >> q;
	LL a[111111], d[111111];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> d[i];
	}
	vector<LL>stoplist;
	for (int i = 1; i < n; i++) {
		if (d[i - 1] == 1 && d[i] == 2) {
			stoplist.emplace_back((a[i - 1] + a[i]) / 2);
		}
	}
	int Q;
	for (int i = 0; i < q; i++) {
		cin >> Q;
		Q--;
		if (d[Q] == 1) {
			LL goal = a[Q] + t;
			bool flag = true;
			for (int j = 0; j < stoplist.size(); j++) {
				if (a[Q] <= stoplist[j] && stoplist[j] <= goal) {
					cout << stoplist[j] << endl;
					flag = false;
					break;
				}
			}
			if (flag) {
				cout << goal << endl;
			}
		}
		else {
			LL goal = a[Q] - t;
			bool flag = true;
			/*for (int j = 0; j < stoplist.size(); j++) {
			if (goal <= stoplist[j] && stoplist[j] <= a[Q]) {
			cout << stoplist[j] << endl;
			flag = false;
			break;
			}
			}*/
			for (int j = stoplist.size() - 1; j >= 0; j--) {
				if (goal <= stoplist[j] && stoplist[j] <= a[Q]) {
					cout << stoplist[j] << endl;
					flag = false;
					break;
				}
			}
			if (flag) {
				cout << goal << endl;
			}
		}
	}
	//system("pause");
}