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>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,t,q,a[100100],d[100100];
ll y[100100];
bool done[100100];
int saiki(int i){
    if(done[i])
        return y[i];

    if(i + d[i] < 0){
        done[i] = true;
        return y[i] = a[i] - t;
    }
    if(i + d[i] >= n){
        done[i] = true;
        return y[i] = a[i] + t;
    }

    if(d[i + d[i]] * d[i] == -1){
        done[i] = true;
        return y[i] = a[i] + d[i] * min(t,abs(a[i + d[i]] - a[i]) / 2);
    }
    y[i] = a[i] + d[i] * min(t,abs(saiki(i + d[i]) - a[i]));
    done[i] = true;
    return y[i];
}
int main(){
    cin >> n >> t >> q;
    REP(i,n){
        cin >> a[i] >> d[i];
        if(d[i] == 2)
            d[i] = -1;
    }
    REP(i,n)
        done[i] = false;
    REP(i,n){
        saiki(i);
    }
    REP(i,q){
        int x;
        cin >> x;
        x--;

        cout << y[x] << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cmath>
#include <queue>

constexpr int MAX_N = 100000;
constexpr long long MAX_T = 1000000000000000000;
constexpr int MAX_Q = 1000;

typedef std::pair<long long, int> P;

int N, Q, target[MAX_Q], count = 0;
long long T, ans[MAX_N];
P p[MAX_N];

void bfs(const long long& pos, const int& i);

void solve();

int main(){
	scanf("%d %lld %d", &N, &T, &Q);

	for(int i = 0; i < N; ++i){
		scanf("%lld %d", &p[i].first, &p[i].second);
	}
	for(int i = 0; i < Q; ++i){
		scanf("%d", &target[i]);
	}

	solve();
	return 0;
}

void solve(){
	for(int i = 0; i < N - 1; ++i){
		if(p[i].second == 1 && p[i + 1].second == 2 && p[i + 1].first - p[i].first <= T * 2){
			int tmp = ans[i] = ans[i + 1] = (p[i + 1].first + p[i].first) / 2;
			for(int j = i - 1; j >= 0; --j){
				if(p[j].second == 1 && tmp - p[j].first <= T){
					ans[j] = tmp;
				}
				else{
					break;
				}
			}
			for(int j = i + 2; j < N; ++j){
				if(p[j].second == 2 && p[j].first - tmp <= T){
					ans[j] = tmp;
				}
				else{
					break;
				}
			}
		}
	}

	for(int i = 0; i < N; ++i){
		if(ans[i] == 0){
			if(p[i].second == 1){
				ans[i] = p[i].first + T;
			}
			else{
				ans[i] = p[i].first - T;
			}
		}
	}

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

C++: #include <bits/stdc++.h>

using namespace std;

#define INF (1LL << 62)

struct Human {
	int direct;
	long long position;
	long long save;
} human[100001];

int main() {
	long long t;
	int n, q;

	cin >> n >> t >> q;
	for (int i = 1; i <= n; ++i) {
		cin >> human[i].position >> human[i].direct;
	}
	human[0].direct = 1;
	human[0].position = -INF;
	human[n + 1].direct = 2;
	human[n + 1].position = INF;

	for (int i = 0; i <= n; ++i) {
		if (human[i].direct == 1 && human[i + 1].direct == 2) {
			long long d = (human[i].position + human[i + 1].position) / 2;
			for (int j = i; j >= 1 && human[j].direct == 1; --j) {
				human[j].save = d;
			}
			for (int j = i + 1; j <= n && human[j].direct == 2; ++j) {
				human[j].save = d;
			}
		}
	}

	int id;
	for (int i = 0; i < q; ++i) {
		cin >> id;
		if (human[id].direct == 1) {
			cout << (human[id].position + t < human[id].save ? human[id].position + t : human[id].save) << endl;
		}
		else {
			cout << (human[id].position - t > human[id].save ? human[id].position - t : human[id].save) << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,t,q;
    cin >> n >> t >> q;
    vi a(n),d(n);
    vector<vi> x(2);
    rep(i,n){
        cin >> a[i] >> d[i];
        d[i]--;
        x[d[i]].push_back(a[i]);
    }
    while(q--){
        int ind;
        cin >> ind;
        ind--;
        if(d[ind]){//西、a[ind]より小さいx[0]の最大
            int p = lower_bound(all(x[0]), a[ind]) - x[0].begin();
            p--;
            if(p < 0){
                cout << a[ind]-t << endl;
            }else{
                //pと衝突する人（ x[0][p]より大きい最小のx[1]）をさがす
                int q = lower_bound(all(x[1]),x[0][p]) - x[1].begin();
                int r = (x[0][p]+x[1][q])/2;//a[ind]が立ち止まる地点
                if(abs(a[ind]-r) <= t)cout << r << endl;
                else cout << a[ind]-t << endl;
            }
        }else{//a[ind]より大きいx[1]の最小
            int p = upper_bound(all(x[1]), a[ind]) - x[1].begin();
            if(p == x[1].size()){
                cout << a[ind]+t << endl;
            }else{
                //pと衝突する人（ x[1][p]より小さい最大のx[0]）をさがす
                int q = lower_bound(all(x[0]),x[1][p]) - x[0].begin();
                q--;
                int r = (x[1][p]+x[0][q])/2;//a[ind]が立ち止まる地点
                if(abs(a[ind]-r) <= t)cout << r << endl;
                else cout << a[ind]+t << endl;
            }
        }
    }
}