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>


int main() {
	int N, T, Q;
	int A[10000], D[10000], X[10000];
	scanf("%d %d %d", &N, &T, &Q);
	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &A[i], &D[i]);
		if (D[i] == 2) D[i] = -1;
	}
	for (int i = 1; i <= Q; i++) {
		scanf("%d", &X[i]);
	}
	for (int i = 1; i <= T; i++) {
		
			for (int j = 1; j <= N; j++) {
				if (D[j] != 0) {
					A[j] += D[j];
					if (A[j] == A[j - 1]) {
						D[j] = 0;
						D[j - 1] = 0;
					}
					if (A[j] == A[j + 1]) {
						D[j] = 0;
						D[j + 1] = 0;
					}
				}
			}
		
	}
	for (int i = 1; i <= Q; i++) {
		printf("%d\n", A[X[i]]);
	}
	
	return 0;
}

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

using namespace std;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, t, q;

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

	while (t > 0) {
		int mini = -1;
		long long mind = 1LL << 62;
		for (int i = 0; i < n - 1; ++i) {
			if (human[i].direct != human[i + 1].direct && human[i].direct != 2 && human[i + 1].direct != 1 && mind > human[i + 1].position - human[i].position) {
				mind = human[i + 1].position - human[i].position;
				mini = i;
			}
		}

		if (mini == -1) { //???????????????????????????
			break;
		}
		else {
			int d;
			if (human[mini].direct == 0 || human[mini + 1].direct == 0) {
				if (t >= mind) {
					d = mind;
				}
				else {
					d = t;
				}
			}
			else {
				if (t >= mind / 2) {
					d = mind / 2;
				}
				else {
					d = t;
				}
			}
			t -= d;

			for (int i = 0; i < n; ++i) {
				if (human[i].direct == 1) {
					human[i].position += d;
				}
				else if (human[i].direct == 2) {
					human[i].position -= d;
				}
			}

			human[mini].direct = human[mini + 1].direct = 0;
		}
	}

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

	return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll N,T,Q,A[100000],D[100000],X[1000];
int main()
{
	scanf("%lld%lld%lld",&N,&T,&Q);
	for(ll i=0;i<N;i++){
		scanf("%lld%lld",&A[i],&D[i]);
	}
	for(ll i=0;i<Q;i++){
		scanf("%lld",&X[i]);
		X[i]--;
	}
	vector<ll> sec;
	for(ll i=0;i<N-1;i++){
		if(D[i]==1&&D[i+1]==2) sec.push_back((A[i]+A[i+1])/2);
	}
	ll ans,id;
	for(ll i=0;i<Q;i++){
		if(D[X[i]]==1){
			ans=A[X[i]]+T;
			id=upper_bound(sec.begin(),sec.end(),A[X[i]])-sec.begin();
			if(id<sec.size()&&sec[id]<ans) ans=sec[id];
		}
		else{
			ans=A[X[i]]-T;
			id=lower_bound(sec.begin(),sec.end(),A[X[i]])-sec.begin()-1;
			if(id>=0&&sec[id]>ans) ans=sec[id];
		}
		printf("%lld\n",ans);
	}
}

C++: #include <bits/stdc++.h>
#define	f first
#define	s second
#define int long long
using namespace	std;
const int INF=LLONG_MAX;
typedef pair<int,int> P;
signed main(){

  vector<int> match;
  P ad[100000];
  int n,t,q,wh[100000];
  cin>>n>>t>>q;
  for(int i=0,a,b;i<n&&cin>>a>>b;i++) ad[i]=P(a,b);
  for(int i=0;i<n-1;i++) if(ad[i].s==1&&ad[i+1].s==2) match.push_back((ad[i].f+ad[i+1].f)/2);
  for(int i=0;i<n;i++){
    if(ad[i].s==1){
      auto it=lower_bound(match.begin(),match.end(),ad[i].f);
      if(it==match.end()) wh[i]=INF;
      else wh[i]=*it;
    }
    else{
      auto it=upper_bound(match.begin(),match.end(),ad[i].f);
      if(it==match.end()) wh[i]=*match.rbegin();
      else if(it==match.begin()) wh[i]=-INF;
      else wh[i]=*(it-1);
    }
  }
  for(int i=0,a;i<q&&cin>>a;i++){
    a--;
    if(ad[a].s==1){
      if(ad[a].f+t<wh[a]) cout<<ad[a].f+t<<endl;
      else cout<<wh[a]<<endl;
    }
    else{
      if(ad[a].f-t>wh[a]) cout<<ad[a].f-t<<endl;
      else cout<<wh[a]<<endl;
    }
  }
  return 0;
}

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

using namespace std;

struct Human {
	int direct;
	int position;
} human[100000];

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

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

	while (t > 0) {
		int mini = -1;
		long long mind = 1LL << 62;
		for (int i = 0; i < n - 1; ++i) {
			if (human[i].direct != human[i + 1].direct && human[i].direct != 2 && human[i + 1].direct != 1 && mind > human[i + 1].position - human[i].position) {
				mind = human[i + 1].position - human[i].position;
				mini = i;
			}
		}

		if (mini == -1) { //???????????????????????????
			break;
		}
		else {
			int d;
			if (human[mini].direct == 0 || human[mini + 1].direct == 0) {
				if (t >= mind) {
					d = mind;
				}
				else {
					d = t;
				}
			}
			else {
				if (t >= mind / 2) {
					d = mind / 2;
				}
				else {
					d = t;
				}
			}
			t -= d;

			for (int i = 0; i < n; ++i) {
				if (human[i].direct == 1) {
					human[i].position += d;
				}
				else if (human[i].direct == 2) {
					human[i].position -= d;
				}
			}

			human[mini].direct = human[mini + 1].direct = 0;
		}
	}

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

	return 0;
}