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 <stdio.h>
#include <algorithm>

long long int N, T, Q;
long long int A[112345], D[112345];
long long int X[1123];
long long int t[112345];

int main(void) {
	scanf("%lld%lld%lld", &N, &T, &Q);
	for (long long int i = 0; i < N; ++i) { scanf("%lld%lld", &A[i], &D[i]); }
	for (long long int i = 0; i < Q; ++i) { scanf("%lld", &X[i]); }

	for (long long int i = 0; i < N - 1; ++i) {
		if (D[i] == 1 && D[i + 1] == 2) {
			long long int t_mem = (A[i] + A[i + 1]) / 2;
			t[i] = t_mem;
			t[i + 1] = t_mem;
			for (long long int j = i - 1; j >= 0; --j) {
				if (D[j] == 1) {
					t[j] = t_mem;
				}
				else { break; }
			}
			for (long long int j = i + 1; j < N; ++j) {
				if (D[j] == 2) {
					t[j] = t_mem;
				}
				else { break; }
			}
		}
	}

	for (long long int i = 0; i < N; ++i) {
		if (t[i] == 0) {
			if (D[i] == 1) {
				t[i] = A[i] + T;
			}
			if (D[i] == 2) {
				t[i] = A[i] - T;
			}
		}
		if(T<std::llabs(A[i]-t[i])){
			if (D[i] == 1) {
				t[i] = A[i] + T;
			}
			if (D[i] == 2) {
				t[i] = A[i] - T;
			}
		}
	}

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

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

int main(){
    
    int N,T,Q;
    cin >> N >> T >> Q;
    
    int WantAnswer[Q];
    vector<int> Houses(N),Direction(N);
    
    for(int i = 0;i < N;i++){
        cin >> Houses.at(i) >> Direction.at(i);
    }
    
    for(int i = 0;i < Q;i++){
        cin >> WantAnswer[i];
        WantAnswer[i]--;
    }
    
    for(int t = 0;t < T;t++){
        for(int n = 0;n < N;n++){
            if(count(Houses.begin(),Houses.end(),Houses[n]) < 2){
                if(Direction[n] == 1){
                    Houses[n]++;
                }else{
                    Houses[n]--;
                }
            }
        }
    }
    
    for(int i = 0;i < Q;i++){
        cout << Houses.at(WantAnswer[i]) << endl;
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef struct{
  int first,second;
  long long place;
}PA;
vector<PA> vec;

void east(int n,long long place){
  if(vec[n].second == 1){
    vec[n].place = place;
    east(n-1,place);
  }
}

void west(int n,long long place){
  if(vec[n].second == 2){
    vec[n].place = place;
    west(n+1,place);
  }
}

int main(){
  int n,q,b,c;
  long long t,a;
      
  scanf("%d %lld %d",&n,&t,&q);
  
  for(int i=0;i<n;i++){
    scanf("%lld %d",&a,&b);
    vec.push_back( (PA){a,b,LLONG_MAX});
  }
  
  for(int i=0;i<n-1;i++){
    if( vec[i].second == 1 && vec[i+1].second == 2){
      vec[i].place = (vec[i].first+vec[i+1].first)/2;
      east(i-1,vec[i].place);
      west(i+1,vec[i].place);
    }
  }

  for(int i=0;i<q;i++){
    scanf("%d",&c);
    c--;
    
    if(vec[c].place == LLONG_MAX || llabs(vec[c].first-vec[c].place) > t){
      if(vec[c].second == 1) cout << vec[c].first+t << endl;
      if(vec[c].second == 2) cout << vec[c].first-t << endl;
    } else cout << vec[c].place << endl;
  }
  return (0);
}

C++: #include<stdio.h>
int main(void)
{
	int n,t,q,a[100001],flgd[1001],Q[1001],x,i;
	scanf("%d%d%d",&n,&t,&q);
	for(i=0;i<n;i++) scanf("%d%d",&a[i],&flgd[i]);
	for(i=0;i<q;i++) scanf("%d",&Q[i]);
	for(i=0;i<n;i++){
	//	printf("%d=%d %d\n",i,flgd[i],flgd[i+1]);
		if(flgd[i]==1&&flgd[i+1]==2){
			flgd[i+1]=0;
			a[i]+=t; a[i+1]-=t;
			if(a[i]>=a[i+1]){
				x=0;
				a[i]-=t; a[i+1]+=t;
				x=(a[i+1]-a[i])/2;
				a[i]+=x; a[i+1]-=x;
			}
		}
		else if(flgd[i]==0&&flgd[i+1]==2){
			flgd[i+1]=0; a[i+1]-=t;
			if(a[i]>=a[i+1]){
				a[i+1]=a[i];
			}
		}
		else{
			if(flgd[i]==1) a[i]+=t;
			if(flgd[i]==2) a[i]-=t;
			flgd[i]=0;
		}
	}
	for(i=0;i<n;i++){
		if(a[i]>a[i+1]){
			a[i]=a[i+1];
		}
	}
	for(i=0;i<q;i++){
		printf("%d\n",a[Q[i]-1]);
	}
	return 0;
}

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

int n, q;
long long t;

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

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

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

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

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

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

	for (int 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;
			}
		}
	}

	for (int i = 0; i < n - 1; i++) {
		if (d[i] == 1 && d[i + 1] == 1) {
			int j = i + 1;

			while (d[j] == 1)
				j++;

			if (j < n - 1) {
				for (int k = i; k < j; k++) {
					if (a[j] - a[k] <= t)
						a[k] = a[j];
					else
						a[k] += t;
				}
				i = j - 1;
			}
			else
				break;
		}
		else if (d[i] == 2 && d[i + 1] == 2) {
			int j = i + 1;
			while (d[j] == 2)
				j++;
			if (i > 0) {
				for (int k = j - 1; k >= i; k--) {
					if (a[k] - a[i] <= t)
						a[k] = a[i];
					else
						a[k] -= t;
				}
			}
			i = j - 1;
		}
	}

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

	return 0;
}