const int N = 1e5;

vector<int> t[2 * N];
#define all(a) (a).begin(), (a).end()

void build( int n, int *a ) { // O(NlogN)
  forn(i, n)
    t[N + i].push_back(a[i]);
  for (int i = N - 1; i > 0; i--) {
    t[i].resize(t[2 * i].size() + t[2 * i + 1].size());
    merge(all(t[2 * i]), all(t[2 * i + 1]), t[i].begin());
  }
}

int inner_get( vector<int> &v, int x, int y ) {
  return upper_bound(all(v), y) - lower_bound(all(v), x);
}

int sum( int l, int r, int x, int y ) { // O(log(R-L))
  int res = 0;
  for (l += N, r += N; l <= r; l >>= 1, r >>= 1) {
    if ((l & 1) == 1) res += inner_get(t[l++], x, y);
    if ((r & 1) == 0) res += inner_get(t[r--], x, y);
  }
  return res;
}