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++: /* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

ll n, t, q;
ll a[100000], d[100000]; 
ll x[100000];
ll s[100000];
ll p[100000];

int main(){
  cin >> n >> t >> q;
  rep(i, n) cin >> a[i] >> d[i];
  rep(i, q) cin >> x[i];

  int ii = -1;
  rep(i, n){
    if (d[i] == 1) ii = i;
    else s[i] = ii;
  }
  
  ii = -1;
  rrep(i, n){
    if (d[i] == 2) ii = i;
    else s[i] = ii;
  }

  rep(i, n){
    if (d[i] == 1){
      if (s[i] == -1) p[i] = a[i] + t;
      else p[i] = min(a[i] + t, (a[s[i]] + a[s[s[i]]]) / 2);
    }
    if (d[i] == 2){
      if (s[i] == -1) p[i] = a[i] - t;
      else p[i] = max(a[i] - t, (a[s[i]] + a[s[s[i]]]) / 2);
    }
  }

  rep(i, q) cout << p[x[i] - 1] << endl;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int n,q,b[100000],i,j,flag=0,min,max,meet[50000],count,person,now=0;
    long long int t,a[100000],tmp,point[50000];
    scanf("%d%lld%d",&n,&t,&q);
    for(i=0; i<n; i++){
        scanf("%lld%d",&a[i],&b[i]);
        if(flag==0){
            if(b[i]==1){
                flag=1;
                count=0;
                meet[count]=i;
            }
        }else{
            if(b[i-1]==1 && b[i]==2){
                point[count]=(a[i-1]+a[i])/2;
            }else if(b[i-1]==2 && b[i]==1){
                count++;
                meet[count]=i;
            }
            if(b[i]==2 && i==n-1){
                count++;
                meet[count]=n;
            }
        }
    }
    for(i=0; i<q; i++){
        scanf("%d",&person);
        flag=0;
        person--;
        for(j=now; j<count; j++){
            if(person<meet[0]){
                tmp=a[person]-t;
                printf("%lld\n",tmp);
                now = j;
                flag=1;
                break;
            }else if(person>=meet[j] && person<meet[j+1]){
                if(llabs(point[j]-a[person]) > t){
                    tmp=(b[person]==1)?(a[person]+t):(a[person]-t);
                }else{
                    tmp=point[j];
                }
                printf("%lld\n",tmp);
                now = j;
                flag = 1;
                break;
            }
        }
        if(flag==0){
            tmp=a[person]+t;
            printf("%lld\n",tmp);
        }
    }
    return 0;
}

C++: //============================================================================
// Name        : JOI.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;

// 1. dp?????????
ll dp[100001];
// 2. n????????????
ll n,t,q;
ll a[100001],d[100001],x;

// ???. calc????????????
ll calc(ll k){
	// 8. dp???????????°??????
	if(dp[k]!=a[k])return dp[k];

	if(d[k]==1){
		if(d[k+1]==1){
			dp[k]=min(calc(k+1),a[k]+t);
		}else{
			dp[k]=min(a[k]+t,(a[k]+a[k+1])/2);
		}
	}else if(d[k]==2){
		if(d[k-1]==2){
			dp[k]=max(calc(k-1),a[k]-t);
		}else{
			dp[k]=max(a[k]-t,(a[k]+a[k-1])/2);
		}
	}
	return dp[k];
}

int main() {

	cin>>n>>t>>q;

	// 3. ?????????
	for(int i=0;i<100001;++i){
			dp[i]=-1;
	}

	// 4.??\???
	for(int i=1; i<n+1; ++i){
		cin>>a[i]>>d[i];
		dp[i]=a[i];
	}


	// 5. ???????????¨??????
	if(d[1]==2){
		dp[1]=a[1]-t;
	}
	if(d[n]==1){
		dp[n]=a[n]+t;
	}

	// 6. ??????
	for(int i=0; i<q; ++i){
		cin>>x;
		cout<<calc(x)<<endl;
	}

	return 0;

}

C++: #include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const int MAX_N = 100000;

ll A[MAX_N], D[MAX_N];
ll stops[MAX_N];

int main() {
	ll N, T, Q;
	cin >> N >> T >> Q;

	ll s = -INF;
	cin >> A[0] >> D[0];
	if (D[0] == 2) stops[0] = s;
	else stops[0] = INF;

	for (int i = 1; i < N; i++) {
		cin >> A[i] >> D[i];

		if (D[i - 1] == 1 && D[i] == 2) {
			s = (A[i] + A[i - 1]) / 2;

			for (int j = i - 1; j >= 0 && D[j] == 1; j--)
				stops[j] = s;
		}
		
		if (D[i] == 2) stops[i] = s;
		else stops[i] = INF;
	}

	for (int i = 0; i < Q; i++) {
		ll x;
		cin >> x;
		x--;
		ll ans;
		if (D[x] == 1) ans = min(A[x] + T, stops[x]);
		else ans = max(A[x] - T, stops[x]);
		cout << ans << endl;
	}
}