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>
using namespace std;
long long N, T, Q, a[1 << 17], b[1 << 17], c[1 << 17];
int main() {
	cin >> N >> T >> Q;
	for (int i = 0; i < N; i++)cin >> a[i] >> b[i];
	long long G = 1LL << 62, H = 1 << 62;
	for (int i = N - 1; i >= 0; i--) {
		if (b[i] == 2)G = a[i];
		if (b[i] == 1) {
			long long C = (a[i] + G) / 2;
			if (C - a[i] >= T)c[i] = a[i] + T;
			else { c[i] = C; }
			if (i >= 1) {
				if (b[i] == b[i - 1])c[i] = H;
			}
			H = c[i];
		}
	}
	G = -1 << 62, H = -1 << 62;
	for (int i = 0; i < N; i++) {
		if (b[i] == 1)G = a[i];
		if (b[i] == 2) {
			long long C = (a[i] + G) / 2;
			if (a[i] - C >= T)c[i] = a[i] + T;
			else { c[i] = C; }
			if (i >= 1) {
				if (b[i] == b[i - 1])c[i] = H;
			}
			H = c[i];
		}
	}
	for (int i = 0; i < Q; i++) {
		int p; cin >> p; p--; cout << c[p] << endl;
	}
	return 0;
}

C++: #include "stdio.h"

int people;
int get;
int now[1000] = {};
long long int place[100001] = {};
long long int time;
int dir[100001] = {};
long long int stop;

int main() {
	scanf("%d %lld %d", &people, &time, &get);
	for (int i = 1; i <= people; i++) {
		scanf("%lld %d", &place[i],&dir[i]);
	//	printf("%lld\n", place[i + 1]);
	}
	for (int i = 0; i < get; i++) {
		scanf("%d", &now[i]);
	//	printf("%lld\n", place[now[i]]);
		if (dir[now[i]] == 1) {
			stop = place[now[i]] + time;
			for (int j = now[i]+1; j <= people; j++) {
				if (dir[j] == 2) {
					if (place[j] - place[j - 1] > time * 2)stop = place[j] - time;
					else stop = place[j] / 2 + place[j - 1] / 2;
					break;
				}
				stop = place[now[i]] + time;
			}
			if (stop > place[now[i]] + time)stop = place[now[i]] + time;
			printf("%lld\n", stop);
		}
		else{
			stop = place[now[i]] - time;
			for (int j = now[i] - 1; j >= 1; j--) {
				if (dir[j] == 1) {
					if (place[j + 1] - place[j] > time * 2)stop = place[j] + time;
					else stop = place[j] / 2 + place[j + 1] / 2;
					break;
				}
				stop = place[now[i]] - time;
			}
			if (stop < place[now[i]] - time)stop = place[now[i]] - time;
			printf("%lld\n", stop);
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

int n;
ll t;
int q;
ll a[100000];
int d[100000];
int x[1000];

int main(){
	scanf("%d%lld%d", &n, &t, &q);
	rep(i, n){
		scanf("%lld%d", &a[i], &d[i]);
	}
	rep(i, q){
		scanf("%d", &x[i]);
	}

	int i = 0;
	while(i < n && d[i] == 2){
		a[i] -= t;
	}
	while(i < n){
		int j = 0;
		while(i + j < n && d[i + j] == 1){
			++j;
		}
		int k = 0;
		while(i + j + k < n && d[i + j + k] == 2){
			++k;
		}
		if(k == 0){
			rep(z, j){
				a[i + z] += t;
			}
		}
		else{
			ll p = (a[i + j - 1] + a[i + j]) / 2;
			rep(z, j){
				a[i + z] = min(a[i + z] + t, p);
			}
			rep(z, k){
				a[i + j + z] = max(a[i + j + z] - t, p);
			}
		}
		i += j + k;
	}

	rep(i, q){
		printf("%lld\n", a[x[i] - 1]);
	}
	return 0;
}

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

using namespace std;

struct Human {
	int direct;
	long long 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;
}

C++: //
//  main.cpp

#include <iostream>
#include <limits.h>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX-1);

int main(){	
	int N,Q;
	ll T;
	cin >> N >> T >> Q;
	
	ll people[1001];
	ll A[100001];
	int D[100001];
	for(int i=0;i<N;i++){
		cin >> A[i] >> D[i];
	}
	for(int i=0;i<Q;i++){
		cin >> people[i];
		people[i]--;
	}
	
	ll east = MIN;
	ll west = MIN;
	ll t;
	for(int i=0;i<Q;i++){
		if(D[people[i]] == 1){
			east = A[people[i]];
			for(ll j=people[i]+1;j<N;j++){
				if(D[j] == 1){
					east = A[j];
				}else{
					t = (east + A[j])/2;
					break;
				}
			}
			if(T < abs(t - A[people[i]])){
				cout << A[people[i]] + T << endl;
			}else{
				cout << t << endl;
			}
		}else{
			west = A[people[i]];
			for(ll j=people[i]-1;j>=0;j--){
				if(D[j] == 1){
					t = (west + A[j])/2;
					break;
				}else{
					west = A[j];
				}
			}
			if(T < abs(A[people[i]] - t)){
				cout << A[people[i]] - T << endl;
			}else{
				cout << t << endl;
			}
//			cout << min(T - (t - A[people[i]]),t - A[people[i]]) << endl;;
		}
	}
	
	/*
	ll answer[100001]={};
	ll lasteast = MIN;
	ll laststate = MIN;
	for(int i=0;i<N;i++){
		if(D[i] == 1){
			if(lasteast == MIN && laststate == MIN){
				answer[i] = A[i] - T;
			}else if(lasteast != MIN && laststate == MIN){
				if(T < abs(abs(lasteast) - abs(A[i]))/2){
					answer[i] = A[i] - T;
				}else{
					answer[i] = (A[i]+lasteast)/2;
				}
			}
		}else{
			
		}
		
	}*/
	
	return 0;
}