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 int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,t,m,a[2],len=2;
    cin >> n >> t >> m;
    int x[101],y[101];
    rep(i,0,n){
        cin >> x[i] >> y[i];
    }
    int memo[101];
    rep(i,0,101){memo[i]=0;}
    rep(j,0,n){
        if(y[j]==2){
            memo[j]=x[j]-t;
        }
        if(y[j]==1){
            memo[j]=x[j]+t;
            for(;j<n;j++){
                memo[j]=x[j]+t;
                if(y[j]==2){
                int wa;
                int butu=(x[j-1]+x[j])/2;
                //cout << butu <<" " << j << "ss";
                //1?????????
                for(int p=j-1;p>=0;p--){
                    if(y[p]==2)break;
                    if((x[p]+t)>=butu){
                        memo[p]=butu;
                    }else{
                        break;
                    }
                }
                int mae = j-1;
                for(;j<n;j++){
                if(y[j]==1){j--;break;}
                if((x[j]-t)<=butu){
                  //  cout << j << endl;
                    memo[j]=butu;
                }else{
                    memo[j]=x[j]-t;
                }
                }
                }
            }
        }
    }
    rep(i,0,m){
        int u;cin >> u;
        cout << memo[u-1] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(in) in.begin(),in.end()
#define int long long
typedef pair<int,int> pii;
signed main(){
    int n,t,q;
    cin >> n >> t >> q;
    vector<pii> l,r;
    vector<int> in(n),d(n);
    rep(i,n){
        cin >> in[i] >> d[i];
        if(d[i] == 1){
            r.push_back(pii(in[i],i));
        }else{
            l.push_back(pii(in[i],i));
        }
    }
    sort(all(l));
    sort(all(r));
    //rep(i,l.size())cout << " " << l[i].first;cout << endl;
    //rep(i,r.size())cout << " " << r[i].first;cout << endl;
    rep(i,q){
        int qq;
        cin >> qq;
        qq--;
        if(d[qq] == 1){
            //lの中からin[qq]以上の最小ind1をさがす
            int tmp1 = upper_bound(all(l), pii(in[qq],-1)) - l.begin();
            if(tmp1 == l.size()){
                cout << in[qq] + t << endl;
                continue;
            }
            int ind1 = l[tmp1].second;
            //rの中からin[ind1]以下の最大ind2をさがす
            int tmp2 = lower_bound(all(r), pii(in[ind1],-1)) - r.begin() - 1;
            int ind2 = r[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(in[qq] + t > x){
                cout << x << endl;
            }else{
                cout << in[qq] + t << endl;
            }
        }else{
            int tmp1 = lower_bound(all(r),pii(in[qq],-1)) - r.begin() - 1;
            if(tmp1 < 0){
                cout << in[qq] - t << endl;
                continue;
            }
            int ind1 = r[tmp1].second;
            int tmp2 = upper_bound(all(l), pii(in[ind1],-1)) - l.begin();
            int ind2 = l[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(x > in[qq] - t){
                cout << x << endl;
            }else{
                cout << in[qq] - t << endl;
            }
        }

    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#define ll long long
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, T, Q; cin >> N >> T >> Q;
	vector <pair<int, int>> A(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i].first >> A[i].second;
		if (A[i].second == 2) A[i].second = -1;
	}
	vector<int> q(Q);
	for (int i = 0; i < Q;i++) cin >> q[i];


	vector<ll> ans(N + 1);
	int f = 0;
	ll l;
	ll mid;
	for (int i = 1; i <= N;i++) {
		if (f == 0 && A[i].second == -1) {
			ans[i] = A[i].first + A[i].second*T;
			continue;
		}
		if (f == 0 && A[i].second == 1) {
			f = 1; l = i;
			continue;
		}
		if (f == 1 && A[i].second == 1) continue;
		if (f == 1 && A[i].second == -1) {
			mid = (A[i].first + A[i - 1].first) / 2;
			ans[i] = max(mid, A[i].first + A[i].second * T);

			for (int at = l; at < i; at++) {
				ans[at] = min(mid, A[at].first + A[at].second*T);
			}
			f = 2;
			continue;
		}
		if (f == 2 && A[i].second == -1) {
			ans[i] = max(mid, A[i].first + A[i].second*T);
			continue;
		}
		if (f == 2 && A[i].second == 1) {
			f = 1; l = i;
			continue;
		}
	}
	if (f == 1) {
		//ans[N] = A[N].first + A[N].second*T;
		for (int at = l; at <= N; at++) {
			ans[at] = A[at].first + A[at].second*T;
		}
	}

	for (int i = 0; i < Q;i++) {
		cout << ans[q[i]] << endl;
	}
}