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>
#define int long long
using namespace std;
 
int N, T, Q;
int A[100001], D[100001];
int X[1001];
int P[100001];  //P[i] = ???i???????????????
 
signed main()
{
    int i, j;
     
    cin >> N >> T >> Q;
    for( i = 1; i <= N; i++ ){
        cin >> A[i] >> D[i];
    }
    for( i = 1; i <= Q; i++ ){
        cin >> X[i];
    }
     
    for( i = N; i >= 1; i-- ){
        if( D[i] == 2 )
            continue;
        //????????????????????????????????????
        if( i == N )
            P[i] = A[i] + T;
        else if( D[i + 1] == 2 )
            P[i] = min(A[i] + T, (A[i] + A[i + 1]) / 2);
        else
            P[i] = min(A[i] + T, P[i + 1]);
    }
    for( i = 1; i <= N; i++ ){
        if( D[i] == 1 )
            continue;
        //????????????????????????????????????
        if( i == 1 )
            P[i] = A[i] - T;
        else if( D[i - 1] == 1 )
            P[i] = max(A[i] - T, (A[i - 1] + A[i]) / 2);
        else
            P[i] = max(A[i] - T, P[i - 1]);
    }
     
    for( i = 1; i <= Q; i++ ){
        cout << P[X[i]] << endl;
    }
    return 0;
}

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

typedef struct {
	long long now; //?????¨??°
	int def; //????§?
} resitants;

int main() {
	int numb = 0;
	int N, Q, imp[1000]; //imp????????????????????????
	long long T;
	resitants R[100000];
	bool stoped[100000]; //??¢?????£????????????????????????
	for (int i = 0; i < 100000; i++) stoped[i] = true;
	cin >> N >> T >> Q;
	for (int i = 0; i < N; i++) { 
		cin >> R[i].now >> R[i].def;
		if (R[i].def == 1) R[i].def = 1;
		else R[i].def = -1;
	}
	for (int i = 0; i < Q; i++) cin >> imp[i];
	for (long long i = 0; i < T; i++) {
		for (int j = 0; j < N; j++) {
			if (stoped[j]) {
				R[j].now += R[j].def;
				if (R[j].now == R[j - 1].now) {
				    stoped[j - 1] = false;
					stoped[j] = false;
				}
				if (R[j].now == R[j + 1].now) {
				    stoped[j + 1] = false;
					stoped[j] = false;
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (i == imp[numb] - 1) {
			cout << R[i].now << endl;
			numb++;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, q, t;
    vector<P> pos;
    vector<ll> ans, ls;
    bool used[MAX_N]{};
    cin >> n >> t >> q;
    REP(i,n){
        ll a, d;
        cin >> a >> d;
        pos.push_back({a,d});
    }
    ans.resize(n);
    ls.push_back(-LLINF);
    REP(i,n-1){
        ll l=pos[i].first, r=pos[i+1].first;
        if(pos[i].second==1 && pos[i+1].second==2 && r-l<=t*2){
            ans[i] = ans[i+1] = (l+r)/2;
            ls.push_back(ans[i]);
            used[i] = used[i+1] = true;
        }
    }
    ls.push_back(LLINF);
    REP(i,n){
        if(!used[i]){
            if(pos[i].second==1){
                ans[i] = min(pos[i].first+t, *lower_bound(ALL(ls),pos[i].first));
            }
            else{
                ans[i] = max(pos[i].first-t, *--lower_bound(ALL(ls),pos[i].first));
            }
        }
    }
    REP(i,q){
        int m;
        cin >> m;
        cout << ans[m-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli inf = 3e18;

int main(){
    lli n,t,q;
    cin >> n >> t >> q;
    vector<lli> a(n), d(n);
    for(int i=0; i<n; i++){
        cin >> a[i] >> d[i];
        if(d[i]==2) d[i]=-1;
    }

    for(int i=0; i<q; i++){
        int p;
        cin >> p;
        p--;
        lli same;
        bool stop = false;
        for(int i=p; i>=0 && i<n; i+=d[p]){
            if(d[i] == d[p]){
                same = a[i];
            }else{
                stop = true;
                lli stopx = (same +a[i])/2;
                if(abs(a[p]-stopx) <= t){
                    cout << stopx << endl;
                }else{
                    cout << a[p] +d[p]*t << endl;;
                }
                break;
            }
        }
        if(!stop){
            cout << a[p] +d[p]*t << endl;
        }
    }
    return 0;
}

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

long long n, q, t;

int d[100000];
long long a[100000], v[1000];

int main()
{
	cin >> n >> t >> q;

	for (long long i = 0; i < n; i++)
		cin >> a[i] >> d[i];

	for (long long i = 0; i < q; i++)
		cin >> v[i];

	for (long long i = 0; i < n - 1; i++) {
		if (d[i] == 1 && d[i + 1] == 2) {
			if (a[i + 1] - a[i] <= t * 2) {
				a[i] = a[i] / 2 + a[i + 1] / 2;
				a[i + 1] = a[i];
			}
			else {
				a[i] += t;
				a[i + 1] -= t;
			}
		}
	}

	long long i = 0;
	while (d[i] == 2) {
		a[i] -= t;
		i++;
	}

	while (i < n - 1) {
		long long j = i;
		while (d[j] == 2 && d[j + 1] == 2) {
			if (a[j + 1] - a[i] <= t)
				a[j + 1] = a[i - 1];
			else
				a[j + 1] -= t;
			j++;
		}
		i = j + 1;
	}

	i = n - 1;
	while (d[i] == 1) {
		a[i] += t;
		i--;
	}

	while (i > -1) {
		long long j = i;
		while (d[j] == 1 && d[j - 1] == 1) {
			if (a[i + 1] - a[j - 1] <= t)
				a[j - 1] = a[i + 1];
			else
				a[j - 1] += t;
			j--;
		}
		i = j - 1;
	}

	for (long i = 0; i < q; i++)
		cout << a[v[i] - 1] << endl;

	return 0;
}