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 <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 999999999

using namespace std;

int n, t, q;

#define int long long

int32_t main(){
	cin >> n >> t >> q;
	vector<int> ea, we;
	int a[n], x[q], maxi, cnt = maxi = 0;
	REP(i, n){
		int an, dn;
		cin >> an >> dn;
		if(dn == 1){
			ea.push_back(an);
			cnt++;
		}
		else{
			we.push_back(an);
		}
		a[i] = an;
		maxi = max(maxi, an);
	}
	ea.push_back(maxi);

	REP(i, q){
		cin >> x[i];
		x[i]--;
	}

	map<int, int> m;
	for(int i = cnt-1; i >= 0; i--){

		int j = upper_bound(we.begin(), we.end(), ea[i]) - we.begin();
		int k = upper_bound(ea.begin(), ea.end(), ea[i]) - ea.begin();		
		if(j == we.size() || ea[k] < we[j]){
			cout << " " << i << endl;
			if(m[ea[k]] <= ea[i] + t && k != ea.size()) m[ea[i]] = m[ea[k]];
			else m[ea[i]] = ea[i] + t;
			continue;
		}

		int r = (ea[i] + we[j])/2;
		if(r <= ea[i]+t){
			m[ea[i]] = m[we[j]] = r;
			

			for(j = j+1; we[j] <= ea[k]; j++){
				if(r >= we[j]-t) m[we[j]] = r;
				else m[we[j]] = we[j] - t;
				
			}
		}
		else{	
			m[ea[i]] = ea[i] + t;
			m[we[i]] = we[i] - t;
			for(j = j+1; j < k; j++){
				m[we[j]] = we[j] - t;
			}
		}
		
		REP(i, n) cout << m[a[i]] << endl;
		cout << endl;
	}

	REP(i, q) cout << m[a[x[i]]] << endl;
}

C++: #include<iostream>
using namespace std;
typedef long long ll;
struct person{ll s,e,d;};
int main(){
  ll n,i,j,k,t,q;
  cin >> n >> t >> q;
  person ps[100001];
  ll p1=-1,p2=-1;
  for(i=0;i<n;i++){
    cin >> ps[i].s >> ps[i].d;
    if(ps[i].d==1) p1=i;
    else{
      ps[i].e=ps[i].s-t;
      if(p1==-1){
      }else if(p2!=-1){
        if(ps[p1].s<ps[p2].s) 
          ps[i].e=max(ps[i].e,ps[p2].e);
        else
          ps[i].e=max(ps[i].e,(ps[i].s+ps[p1].s)/2);
      }else{
        ps[i].e=max(ps[i].e,(ps[i].s+ps[p1].s)/2);
      }
      p2=i;
    }
  }
  p1=-1;p2=-1;
  for(i=n-1;i>=0;i--){
    if(ps[i].d==2) p2=i;
    else{
      ps[i].e=ps[i].s+t;
      if(p2==-1){
      }else if(p1!=-1){
        if(ps[p1].s<ps[p2].s) 
          ps[i].e=min(ps[i].e,ps[p1].e);
        else
          ps[i].e=min(ps[i].e,(ps[i].s+ps[p2].s)/2);
      }else{
        ps[i].e=min(ps[i].e,(ps[i].s+ps[p2].s)/2);
      }
      p1=i;
    }
  }
  //cout<<endl;
  /*
  for(i=0;i<n;i++){
    cout << ps[i].e << endl;
  }
  cout << endl;
  */
  for(i=0;i<q;i++){
    cin >> k;
    cout << ps[k-1].e << endl;
  }
  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

ll n,t,q;
struct person{
  int id,dir;
  ll pos;
  person *b,*n;
  void move(){
    if(dir == 1){
      if(n == nullptr){
        pos += t;
        dir = 3;
      }
      else if(n->dir == 2){
        if(abs((pos + n->pos)/2 - pos) <= t){
          pos = n->pos = (pos+n->pos)/2;
        }
        else{
          pos += t;
          n->pos -= t;
        }
        dir = 3,n->dir = 3;
      }
      else if(n->dir == 3){
        if(abs(n->pos - pos) <= t){
          pos = n->pos;
        }
        else{
          pos += t;
        }
        dir = 3,n->dir = 3;
      }
    }
    else if(dir == 2){
      if(b == nullptr){
        pos -= t;
        dir = 3;
      }
      else if(b->dir == 3){
        if(abs(pos - b->pos) <= t){
          pos = b->pos;
        }
        else{
          pos -= t;
        }
        dir = 3,b->dir = 3;
      }
    }
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> t >> q;
  vector<person> p(n);
  vector<ll> obs(q);
  rep(i,n){
    p[i].id = i;
    cin >> p[i].pos >> p[i].dir;
  }
  REP(i,1,n-1){
    p[i].b = &p[i-1];
    p[i].n = &p[i+1];
  }
  p[0].b = nullptr;
  p[0].n = &p[1];
  p[n-1].b = &p[n-2];
  p[n-1].n = nullptr;
  rep(i,q){
    cin >> obs[i];
    obs[i]--;
  }
  ll k = 0;
  while(k < 100){
    ++k;
    ll cnt = 0;
    rep(i,n){
      p[i].move();
      if(p[i].dir == 3){
         ++cnt;
      }
    }
    if(cnt == n){
      break;
    }
  }
  rep(i,q){
    cout << p[obs[i]].pos << endl;
  }
  return 0;
}