Problem:
JOI国のお散歩事情 (Walking in JOI Kingdom)
問題
JOI 国には東西に走る 1 本の十分に長い道路がある．JOI 国の王宮が道路沿いにあり，JOI 国における道路沿いの位置は整数 A で表される．A = 0 のときは王宮の位置を表す．A > 0 のときは，王宮から東へ A メートル進んだ位置を表す．A < 0 のときは，王宮から西へ -A メートル進んだ位置を表す．
JOI 国の道路沿いには N 軒の家があり，家には西から順に 1 から N までの番号が付けられている．JOI 国には N 人の国民がいて，国民には 1 から N までの番号が付けられている．家 i には国民 i が住んでいる．家 i の位置は 0 でない偶数 A
i
で表される．A
1
, ..., A
N
は全て異なる．
JOI 国では，近年国民の運動不足が問題になっている．国民の健康が気になった JOI 国の王様は，国民全員に散歩をする命令を出した．王様が命令を出すと，全ての国民は一斉に東向きまたは西向きに歩き始める．それぞれの国民がどちらの向きに歩き始めるかは，国民ごとに決まっている．全ての国民は，歩くときは 1 秒あたり 1 メートルの速度で歩く．
JOI 国の国民は皆おしゃべりが大好きである．散歩の途中にほかの国民に出会うと，その場所で立ち止まって世間話を始めてしまう．すでに立ち止まっている国民に出会った場合も同様である．一度立ち止まった国民は，再び歩き出すことはない．
JOI 国には Q 人の重要人物がいる．JOI 国の王様は，命令が出されてから T 秒後の，Q 人の重要人物の位置を把握しておきたい．命令が出されてから T 秒後の，Q 人の重要人物の位置を求めるプログラムを作成せよ．
入力
入力は，1 + N + Q 行からなる．
1 行目には，3 つの整数 N，T，Q (1 ≦ N ≦ 100000 (= 10
5
), 0 ≦ T ≦ 10
18
, 1 ≦ Q ≦ 1000，1 ≦ Q ≦ N) が空白を区切りとして書かれている．これは，JOI 国に家が N 軒あり，王様が命令を出してから T 秒後の，Q 人の重要人物の位置を把握しておきたいことを表す．
続く N 行のうち i 行目には，2 つの整数 A
i
, D
i
(-10
18
≦ A
i
≦ 10
18
, A
i
は 0 でない偶数, 1 ≦ D
i
≦ 2) が空白を区切りとして書かれている．A
i
は家 i の位置を表す偶数である．すべての i (1 ≦ i ≦ N - 1) について，A
i
< A
i+1
を満たす．D
i
は命令が出された後に国民 i が歩き始める方向を表す．D
i
= 1 のときは国民 i は東向きに歩き始める．D
i
= 2 のときは国民 i は西向きに歩き始める．
続く Q 行のうち i 行目には，整数 X
i
(1 ≦ X
i
≦ N) が書かれている．これは，i 番目の重要人物が家 X
i
に住んでいることを表す．すべての i (1 ≦ i ≦ Q - 1) について，X
i
< X
i+1
を満たす．
与えられる 5 つの入力データのうち，入力 1 では N ≦ 100，T ≦ 10000を満たす．また，入力 2 では N ≦ 5000 を満たす．また，入力 3 では，ある整数 M (1 ≦ M ≦ N - 1) があって，すべての i (1 ≦ i ≦ M) について D
i
= 1，すべての j (M + 1 ≦ j ≦ N) について D
j
= 2 を満たす．また，入力 1，2，3 では，入力に与えられる整数の絶対値は 1000000000 (= 10
9
) を超えない．入力 4，5 では，与えられる整数が 32 ビット符号付き整数の範囲に収まらないことに注意せよ．
出力
出力は Q 行からなる．
i 行目 (1 ≦ i ≦ Q) には，王様が命令を出してから T 秒後の，i 番目の重要人物の位置を表す整数を出力せよ．この値が整数であることは，問題文の条件より保証されている．
入出力例
入力例 1
5 5 3
-8 1
-4 2
-2 2
4 2
10 1
1
3
5
出力例 1
-6
-6
15
入力例 2
7 18 5
-100 1
-56 2
-34 1
-30 1
-22 1
-4 2
18 2
1
3
4
5
7
出力例 2
-82
-16
-13
-13
0
情報オリンピック日本委員会作 『第 15 回日本情報オリンピック JOI 2015/2016 予選競技課題』

Submitted solutions:

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	auto N=in(),T=in(),Q=in();
	vll E,W;
	vector<pair<ll,ll>> A(N);
	REP(i,N){
		auto P=in(),D=in();
		if(D==1) E.push_back(P);
		else W.push_back(P);
		A[i].first=P;
		A[i].second=D;
	}
	sort(ALL(E));
	sort(ALL(W));

	map<ll,ll> C;
	REP(i,E.size()){
		auto res = lower_bound(ALL(W),E[i]);
		if(res==W.end()) continue;
		C[*res] = E[i];
	}
	vll S;
	for(auto [w,e]:C){
		ll sp=(w+e)/2ll;
		S.emplace_back(sp);
	}
	sort(ALL(S));

	LOOP(Q){
		auto X=in()-1;
		if(A[X].second==1){
			auto res = lower_bound(ALL(S),A[X].first);
			if(res==S.end()){
				out(A[X].first+T);
			}
			else{
				if((*res)-A[X].first<=T){
					out(*res);
				}
				else{
					out(A[X].first+T);
				}
			}
		}
		else{
			auto res = lower_bound(ALL(S),A[X].first);
			if(res==S.begin()){
				out(A[X].first-T);
			}
			else{
				res--;
				if(A[X].first-(*res)<=T){
					out(*res);
				}
				else{
					out(A[X].first-T);
				}
			}
		}
	}

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7284
final_rank: 18

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, T, Q;
  cin >> N >> T >> Q;
  vi A(N+2), D(N+2), X(Q);
  rep(i, 1, N+1) cin >> A[i] >> D[i];
  A[0] = -inf;
  D[0] = 1;
  A[N+1] = inf;
  D[N+1] = 2;
  rep(i, Q) cin >> X[i];
  vi p(N+2);
  rep(i, N+1) {
    if ((D[i] == 1) and (D[i+1] == 2)) {
      ll t = (A[i] + A[i+1]) / 2;
      rrep(j, 0, i+1) {
        if (D[j] == 1) p[j] = t;
        else break;
      }
      rep(j, i+1, N+2) {
        if (D[j] == 2) p[j] = t;
        else break;
      }
    }
  }
  rep(i, Q) {
    ll j = X[i];
    if (D[j] == 1) {
      print(min(A[j]+T, p[j]));
    } else {
      print(max(A[j]-T, p[j]));
    }
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5404
final_rank: 17

code_snippet: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  vector<ll> people(1001);
  vector<ll> A(100001);
  vector<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 << '\n';
      } else {
        cout << t << '\n';
      }
    } 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 << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4388
final_rank: 4

code_snippet: #include <iostream>
#include <limits.h>
#include <vector>

using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int N, Q;
  ll T;
  cin >> N >> T >> Q;

  vector<ll> people(Q);
  vector<ll> A(N);
  vector<int> D(N);

  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++) {
    ll person = people[i];
    ll person_pos = A[person];
    int direction = D[person];

    if (direction == 1) {
      east = person_pos;
      
      for (ll j = person + 1; j < N; j++) {
        if (D[j] == 1) {
          east = A[j];
        } else {
          t = (east + A[j]) / 2;
          break;
        }
      }
      
      if (T < abs(t - person_pos)) {
        cout << person_pos + T << '\n';
      } else {
        cout << t << '\n';
      }
    } else {
      west = person_pos;
      
      for (ll j = person - 1; j >= 0; j--) {
        if (D[j] == 1) {
          t = (west + A[j]) / 2;
          break;
        } else {
          west = A[j];
        }
      }
      
      if (T < abs(person_pos - t)) {
        cout << person_pos - T << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4392
final_rank: 6

code_snippet: #include <iostream>
#include <limits.h>
using std::cin;
using std::cout;
using std::endl;

using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);

int main() {
  int N, Q;
  ll T;
  cin >> N >> T >> Q;

  ll* people = new ll[Q];
  ll* A = new ll[N];
  int* D = new int[N];

  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;
  ll abs_diff;

  for (int i = 0; i < Q; i++) {
    if (D[people[i]] == 1) {
      east = A[people[i]];
      ll max_east = east;

      for (ll j = people[i] + 1; j < N; j++) {
        if (D[j] == 1) {
          east = A[j];
          max_east = east > max_east ? east : max_east;
        } else {
          t = (max_east + A[j]) / 2;
          break;
        }
      }

      abs_diff = abs(t - A[people[i]]);
      if (T < abs_diff) {
        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];
        }
      }

      abs_diff = abs(A[people[i]] - t);
      if (T < abs_diff) {
        cout << A[people[i]] - T << endl;
      } else {
        cout << t << endl;
      }
    }
  }

  delete[] people;
  delete[] A;
  delete[] D;

  return 0;
}
accuracy: 0.6
time_ms: 50
memory_kb: 4356
final_rank: 19

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

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

  int N, Q;
  ll T;
  cin >> N >> T >> Q;

  std::vector<ll> people(Q);
  std::vector<ll> A(N);
  std::vector<int> D(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i] >> D[i];
  }

  // Fill people array in the same loop where its elements are read
  for (int i = 0; i < Q; i++) {
    cin >> people[i];
    people[i]--;
  }

  ll east = MIN;
  ll west = MIN;
  ll t = 0;

  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 << '\n';
      } else {
        cout << t << '\n';
      }
    } 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 << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4388
final_rank: 4

code_snippet: #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 A[100001];
  int D[100001];
  ll east, west, t;
  ll results[1001];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> D[i];
  }
  for (int i = 0; i < Q; i++) {
    int people;
    cin >> people;
    people--;
    if (D[people] == 1) {
      east = A[people];
      for (ll j = people + 1; j < N; j++) {
        if (D[j] == 1) {
          east = A[j];
        } else {
          t = (east + A[j]) / 2;
          break;
        }
      }
      if (T < abs(t - A[people])) {
        results[i] = A[people] + T;
      } else {
        results[i] = t;
      }
    } else {
      west = A[people];
      for (ll j = people - 1; j >= 0; j--) {
        if (D[j] == 1) {
          t = (west + A[j]) / 2;
          break;
        } else {
          west = A[j];
        }
      }
      if (T < abs(A[people] - t)) {
        results[i] = A[people] - T;
      } else {
        results[i] = t;
      }
    }
  }
  for (int i = 0; i < Q; i++) {
    cout << results[i] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4532
final_rank: 13

code_snippet: #include <iostream>
#include <limits.h>
#include <vector>
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;
  vector<ll> people(Q);
  vector<ll> A(N);
  vector<int> D(N);
  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) {
    ll diff;
    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;
        }
      }
      diff = abs(t - A[people[i]]);
      if (T < diff) {
        cout << A[people[i]] + T << "\n";
      } else {
        cout << t << "\n";
      }
    } 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];
        }
      }
      diff = abs(A[people[i]] - t);
      if (T < diff) {
        cout << A[people[i]] - T << "\n";
      } else {
        cout << t << "\n";
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4392
final_rank: 8

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  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++) {
    ll current_person = A[people[i]];
    if (D[people[i]] == 1) {
      east = current_person;
      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 - current_person)) {
        cout << current_person + T << "\n";
      } else {
        cout << t << "\n";
      }
    } else {
      west = current_person;
      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(current_person - t)) {
        cout << current_person - T << "\n";
      } else {
        cout << t << "\n";
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4628
final_rank: 11

code_snippet: #include <iostream>
#include <limits.h>
using namespace std;

int main() {
  int N, Q;
  int T;
  cin >> N >> T >> Q;
  int* people = new int[Q];
  int* A = new int[N];
  int* D = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> D[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> people[i];
    people[i]--;
  }
  int t;
  for (int i = 0; i < Q; i++) {
    if (D[people[i]] == 1) {
      int east = A[people[i]];
      for (int 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 {
      int west = A[people[i]];
      for (int j = people[i] - 1; j >= 0; j--) {
        if (D[j] != 1) {
          west = A[j];
        } else {
          t = (west + A[j]) / 2;
          break;
        }
      }
      if (T < abs(A[people[i]] - t)) {
        cout << A[people[i]] - T << endl;
      } else {
        cout << t << endl;
      }
    }
  }
  delete[] people;
  delete[] A;
  delete[] D;
  return 0;
}
accuracy: 0.6
time_ms: 2880
memory_kb: 19316
final_rank: 20

code_snippet: #include <iostream>

using namespace std;
using ll = long long;

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, west, 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]) >> 1;
          break;
        }
      }
      ll diff = abs(t - A[people[i]]);
      if (T < diff) {
        cout << A[people[i]] + T << '\n';
      } else {
        cout << t << '\n';
      }
    } else {
      west = A[people[i]];
      for (ll j = people[i] - 1; j >= 0; j--) {
        if (D[j] == 1) {
          t = (west + A[j]) >> 1;
          break;
        } else {
          west = A[j];
        }
      }
      ll diff = abs(A[people[i]] - t);
      if (T < diff) {
        cout << A[people[i]] - T << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4504
final_rank: 12

code_snippet: #include <iostream>
using namespace std;
using ll = long long;

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 t;
  for (int i = 0; i < Q; i++) {
    if (D[people[i]] == 1) {
      ll 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]) >> 1;
          break;
        }
      }
      ll diff = abs(t - A[people[i]]);
      if (T < diff) {
        cout << A[people[i]] + T << endl;
      } else {
        cout << t << endl;
      }
    } else {
      ll west = A[people[i]];
      for (ll j = people[i] - 1; j >= 0; j--) {
        if (D[j] == 1) {
          t = (west + A[j]) >> 1;
          break;
        } else {
          west = A[j];
        }
      }
      ll diff = abs(A[people[i]] - t);
      if (T < diff) {
        cout << A[people[i]] - T << endl;
      } else {
        cout << t << endl;
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4600
final_rank: 14

code_snippet: #include <iostream>
using namespace std;
using ll = long long;

int main() {
  int N, Q;
  ll T;
  cin >> N >> T >> Q;

  ll *people = new ll[Q];
  ll *A = new ll[N];
  int *D = new int[N];

  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 t;
  for (int i = 0; i < Q; i++) {
    if (D[people[i]] == 1) {
      ll 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;
        }
      }
      ll diff = abs(t - A[people[i]]);
      if (T < diff) {
        cout << A[people[i]] + T << endl;
      } else {
        cout << t << endl;
      }
    } else {
      ll 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];
        }
      }
      ll diff = abs(A[people[i]] - t);
      if (T < diff) {
        cout << A[people[i]] - T << endl;
      } else {
        cout << t << endl;
      }
    }
  }

  delete[] people;
  delete[] A;
  delete[] D;

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4396
final_rank: 9

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <tuple>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cassert>
#include <functional>
#include <numeric>
#include <type_traits>
#include <optional>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define coutf(f) cout << fixed << setprecision(f)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

int main() {
	const ll INF = 1LL << 60;
	ll n, t, q;
	cin >> n >> t >> q;
	vector<ll> a(n), d(n);
	rep(i, n) cin >> a[i] >> d[i];
	vector<ll> col;
	col.push_back(-INF);
	rep(i, n - 1) {
		if (d[i] == 1 && d[i+1] == 2) {
			col.push_back((a[i] + a[i + 1]) / 2);
		}
	}
	col.push_back(INF);
	rep(i, q) {
		int x;
		cin >> x;
		x--;
		if (d[x] == 1) {
			auto iter = lower_bound(all(col), a[x]);
			cout << min(*iter, a[x] + t) << endl;
		}
		else {
			auto iter = upper_bound(all(col), a[x]);
			iter--;
			cout << max(*iter, a[x] - t) << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 5068
final_rank: 16

code_snippet: #include <iostream>
#include <limits.h>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  ll* people = new ll[Q];
  ll* A = new ll[N];
  int* D = new int[N];
  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 << '\n';
      } else {
        cout << t << '\n';
      }
    } 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 << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  delete[] people;
  delete[] A;
  delete[] D;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4396
final_rank: 7

code_snippet: #include <iostream>
#include <limits.h>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  ll* A = new ll[N];
  int* D = new int[N];
  ll* people = new ll[Q];
  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 (int 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 << "\n";
      } else {
        cout << t << "\n";
      }
    } else {
      west = A[people[i]];
      for (int 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 << "\n";
      } else {
        cout << t << "\n";
      }
    }
  }
  delete[] A;
  delete[] D;
  delete[] people;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4344
final_rank: 3

code_snippet: #include <iostream>
#include <limits.h>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);
int main() {
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  ll *people = new ll[Q];
  ll *A = new ll[N];
  int *D = new int[N];
  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++) {
    int k = people[i];
    if (D[k] == 1) {
      east = A[k];
      for (ll j = k + 1; j < N; j++) {
        if (D[j] == 1) {
          east = A[j];
        } else {
          t = (east + A[j]) / 2;
          break;
        }
      }
      if (T < abs(t - A[k])) {
        cout << A[k] + T << '\n';
      } else {
        cout << t << '\n';
      }
    } else {
      west = A[k];
      for (ll j = k - 1; j >= 0; j--) {
        if (D[j] == 1) {
          t = (west + A[j]) / 2;
          break;
        } else {
          west = A[j];
        }
      }
      if (T < abs(A[k] - t)) {
        cout << A[k] - T << '\n';
      } else {
        cout << t << '\n';
      }
    }
  }
  delete[] people;
  delete[] A;
  delete[] D;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4324
final_rank: 2

code_snippet: #include <iostream>
#include <limits.h>
using namespace std;
using ll = long long;
constexpr ll MIN = -(LLONG_MAX - 1);
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    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;
    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) {
                    t = (east + A[j]) / 2;
                    break;
                }
                east = A[j];
            }
            if (T < abs(t - A[people[i]])) {
                cout << A[people[i]] + T << '\n';
            } else {
                cout << t << '\n';
            }
        } else {
            ll west = A[people[i]];
            for (ll j = people[i] - 1; j >= 0; j--) {
                if (D[j] == 1) {
                    t = (west + A[j]) / 2;
                    break;
                }
                west = A[j];
            }
            if (T < abs(A[people[i]] - t)) {
                cout << A[people[i]] - T << '\n';
            } else {
                cout << t << '\n';
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4640
final_rank: 10

code_snippet: #include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
using ll = long long;
const ll MIN = -(LONG_LONG_MAX - 1);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  vector<ll> people(Q);
  vector<ll> A(N);
  vector<int> D(N);
  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 << "\n";
      } else {
        cout << t << "\n";
      }
    } 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 << "\n";
      } else {
        cout << t << "\n";
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4260
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <limits>

using namespace std;
using ll = long long;
const ll MIN = -(numeric_limits<ll>::max() - 1);

int main() {
    int N, Q;
    ll T;
    cin >> N >> T >> Q;
    vector<ll> people(Q), A(N), D(N);
    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 << '\n';
            } else {
                cout << t << '\n';
            }
        } 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 << '\n';
            } else {
                cout << t << '\n';
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4660
final_rank: 15