Language: C++

#ifndef ___Class_RangeTree
#define ___Class_RangeTree

// ------ Includes ------ //
#include <limits>
#include <vector>
#include <algorithm>

template<typename Type> class RangeTree {
private:
	int size_; std::vector<std::vector<Type> > dat;
	inline int query_(int a, int b, Type x, int k, int l, int r) {
		// Find range [a, b) : value < x : Now k-th node and the range is [l, r)
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return lower_bound(dat[k].begin(), dat[k].end(), x);
		int lc = query_(a, b, (k << 1), l, (l + r) >> 1);
		int rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
		return lc + rc;
	}
public:
	RangeTree() : size_(0), dat(std::vector<Type>()) {};
	template<class T>
	RangeTree(T begin_, T end_) {
		int n = (end_ - begin_);
		for (size_ = 1; size_ < n; size_ <<= 1); dat.resize(size_ << 1, std::vector<Type>());
		for (int i = 0; i < n; i++) dat[i + size_] = std::vector<Type>({ *(begin_ + i) });
		for (int i = size_ - 1; i > 0; i--) std::merge(dat[i << 1].begin(), dat[i << 1].end(), dat[(i << 1) + 1].begin(), dat[(i << 1) + 1].end(), dat[i].begin());
	}
	inline int size() { return size_; }
	inline int query(int l, int r, Type x) {
		// Find range [a, b) : value < x
		return query_(l, r, x, 1, 0, size_);
	}
};

#endif

#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
typedef long long ll;
const ll inf = (1LL << 61);
struct edge { int to; ll cost; };
const bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int N, M, Q, a, b, c; ll z1, z2; vector<edge> G[100009];
vector<ll> dist(int s) {
	vector<ll> ret(N, inf); ret[s] = 0;
	priority_queue<edge> que; que.push(edge{ s, 0 });
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				que.push(edge{ e.to, -ret[e.to] });
			}
		}
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &a, &b, &c);
		G[a].push_back(edge{ b, c });
		G[b].push_back(edge{ a, c });
	}
	vector<ll> res1 = dist(0);
	vector<ll> res2 = dist(N - 1);
	vector<pair<ll, ll> > x0(N);
	for (int i = 0; i < N; i++) x0[i] = make_pair(res2[i], res1[i]);
	sort(x0.begin(), x0.end());
	vector<ll> x1(N), x2(N);
	for (int i = 0; i < N; i++) x1[i] = x0[i].second, x2[i] = x0[i].first;
	RangeTree<ll> q(x1.begin(), x1.end());
	scanf("%d", &Q);
	while (Q--) {
		scanf("%lld%lld", &z1, &z2);
		int ptr = lower_bound(x2.begin(), x2.end(), z2) - x2.begin();
		printf("%d\n", q.query(ptr, N, z1 + 1));
	}
	return 0;
}

Compiler output:
a.cc: In instantiation of 'int RangeTree<Type>::query_(int, int, Type, int, int, int) [with Type = long long int]':
a.cc:32:10:   required from 'int RangeTree<Type>::query(int, int, Type) [with Type = long long int]'
   32 |                 return query_(l, r, x, 1, 0, size_);
      |                        ^~~~~~
a.cc:83:25:   required from here
   83 |                 printf("%d\n", q.query(ptr, N, z1 + 1));
      |                                ~~~~~~~^~~~~~~~~~~~~~~~
a.cc:15:57: error: cannot convert '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >' to 'int' in return
   15 |                 if (a <= l && r <= b) return lower_bound(dat[k].begin(), dat[k].end(), x);
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                         |
      |                                                         __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >
a.cc:16:32: error: no matching function for call to 'RangeTree<long long int>::query_(int&, int&, int, int&, int)'
   16 |                 int lc = query_(a, b, (k << 1), l, (l + r) >> 1);
      |                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:12:20: note: candidate: 'int RangeTree<Type>::query_(int, int, Type, int, int, int) [with Type = long long int]'
   12 |         inline int query_(int a, int b, Type x, int k, int l, int r) {
      |                    ^~~~~~
a.cc:12:20: note:   candidate expects 6 arguments, 5 provided
a.cc:17:32: error: no matching function for call to 'RangeTree<long long int>::query_(int&, int&, int, int, int&)'
   17 |                 int rc = query_(a, b, (k << 1) + 1, (l + r) >> 1, r);
      |                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:12:20: note: candidate: 'int RangeTree<Type>::query_(int, int, Type, int, int, int) [with Type = long long int]'
   12 |         inline int query_(int a, int b, Type x, int k, int l, int r) {
      |                    ^~~~~~
a.cc:12:20: note:   candidate expects 6 arguments, 5 provided