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 <iostream>
#include <queue>
#include <set>
using namespace std;

struct person{
    long long start;
    long long end;
    long long way;
    bool finished;
};
person person[100005];
long long n,t,q,key[1005];
int main(){
    //cout<<endl;
    cin>>n>>t>>q;
    priority_queue<long long> crash;
    crash.push(-10000000000000000);
    for(int i=1; i<=n; i++) {cin>>person[i].start>>person[i].way; person[i].finished=false;}
    for(int i=1; i<=n; i++){
        if(i==1&&person[i].way==2) {person[i].end=person[i].start-t; person[i].finished=true; continue;}
        if(person[i].way==2){
            if(person[i-1].way==1){
                if((person[i].start-person[i-1].start)/2>t) {
                    person[i].end=person[i].start-t;
                    person[i-1].end=person[i-1].start+t;
                }else{
                    person[i].end=(person[i].start+person[i-1].start)/2;
                    person[i-1].end=(person[i].start+person[i-1].start)/2;
                    crash.pop();
                    crash.push((person[i].start+person[i-1].start)/2);
                    for(int j=1; j<i-1; j++){
                        if(person[j].finished!=true&&person[j].way==1) {
                            if(person[j].start+t>=crash.top()){person[j].end=crash.top(); person[j].finished=true;}
                            else person[j].end=person[j].start+t; person[j].finished=true;
                        }
                    }
                }
                person[i].finished=true;
                person[i-1].finished=true;
                continue;
            }else if(person[i].start-t<=crash.top()) {person[i].end=crash.top(); person[i].finished=true; continue;
            }else {
                person[i].end=person[i].start-t;
                person[i].finished=true;
            }}
    }
    for(int i=1; i<=n; i++){
        if(person[i].finished!=true){
            if(person[i].way==1) {person[i].end=person[i].start+t; person[i].finished=true;}
            else {person[i].end=person[i].start-t; person[i].finished=true;}
        }
    }
    //for(int i=1; i<=n; i++) cout<<"person["<<i<<"].end=="<<person[i].end<<endl;
    for(int i=1; i<=q; i++) {
        cin>>key[i];
        cout<<person[key[i]].end<<endl;
    }
}

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

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
// 1. dp?????????
ll dp[100001];
// 2. n?????????
ll N,T,Q;
ll A[100001];
int D[100001];

// 7. calc?????????
ll calc(int k){
	// 8. dp???????????°??????
	if(dp[k]!=A[k])return dp[k];
	// 9. dp????¨????

	if(D[k]==1){
		if(D[k+1]==1){
			dp[k]=min(A[k]+T,calc(k+1));
		}else{
			dp[k]=min((A[k]+A[k+1])/2,A[k]+T);
		}
	}
	if(D[k]==2){
		if(D[k-1]==2){
			dp[k]=max(A[k]-T,calc(k-1));
		}else{
			dp[k]=max((A[k]+A[k-1])/2,A[k]-T);
		}
	}

	return dp[k];
}
int main() {
	cin>>N>>T>>Q;

	//3.?????????

	//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]-=T;
	}

	if(D[N]==1){
		dp[N]+=T;
	}


	//6.??????
	int X;
	for(int i=1;i<Q+1;i++){
		cin>>X;
		cout<<calc(X)<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(void){
    int n,q;
    long long t;
    cin>>n>>t>>q;
    vector<pair<int,int> >c(n);
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
        cin>>c[i].first>>c[i].second;
        if(c[i].second==2)c[i].second=-1;
    }
    for (int i = 0; i < n; ++i) {
        if(c[i].second!=c[i+1].second)ans.push_back((c[i].first+c[i+1].first)/2);
    }
    for (int i = 0; i < q; ++i) {
        int a;
        cin>>a;a=a-1;
        for (int j = 0; j < ans.size(); ++j) {
            if(c[a].second==1){
                if(c[a].first<ans[j]){
                    if(abs(ans[j]-c[a].first)<t){cout<<ans[j]<<endl;break;}
                    else {cout<<t*c[a].second+c[a].first<<endl;break;}
                }
            }
            else {
                if(c[a].first>ans[j]){
                    if(abs(ans[j]-c[a].first)<t){cout<<ans[j]<<endl;break;}
                    else {cout<<t*c[a].second+c[a].first<<endl;break;}
                }
            }
        }
    }
    return 0;
}