Language: C++

class RangeIndex {
public:
	RangeIndex(int n) {
		m_indexes.resize(n);
		for (auto &row : m_indexes) {
			row.resize(n, 0);
		}
	}

	int getTrainsNum(const int p, const int q) {
		return m_indexes[p - 1][q - 1];
	}

	void addTrains(const std::vector<std::pair<int, int>> &trains) {
		for (const auto &train : trains) {
			addTrain(train.first, train.second);
		}
	}

private:
	std::vector<std::vector<int>> m_indexes;

	void addTrain(const int l, const int r) {
		for (int i = 0; i <= (l - 1); ++i) {
			for (int j = (r - 1); j < static_cast<int>(m_indexes.size()); ++j) {
				++m_indexes[i][j];
			}
		}
	}
};

void outputResult(const int n, const std::vector<std::pair<int, int>> &trains,
	const std::vector<std::pair<int, int>> &ranges) {
	RangeIndex index(n);
	index.addTrains(trains);
	for (const auto &range : ranges) {
		std::cout << index.getTrainsNum(range.first, range.second) << std::endl;
	}
}

int main() {
	int n, m, q;
	std::cin >> n >> m >> q;
	std::vector<std::pair<int, int>> trains(m);
	for (int i = 0; i < m; ++i) {
		int l, r;
		std::cin >> l >> r;
		trains[i] = std::make_pair(l, r);
	}
	std::vector<std::pair<int, int>> ranges(q);
	for (int i = 0; i < q; ++i) {
		int l, r;
		std::cin >> l >> r;
		ranges[i] = std::make_pair(l, r);
	}
	outputResult(n, trains, ranges);
	return 0;
}

Compiler output:
a.cc:14:35: error: 'vector' in namespace 'std' does not name a template type
   14 |         void addTrains(const std::vector<std::pair<int, int>> &trains) {
      |                                   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | class RangeIndex {
a.cc:14:41: error: expected ',' or '...' before '<' token
   14 |         void addTrains(const std::vector<std::pair<int, int>> &trains) {
      |                                         ^
a.cc:21:14: error: 'vector' in namespace 'std' does not name a template type
   21 |         std::vector<std::vector<int>> m_indexes;
      |              ^~~~~~
a.cc:21:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   21 |         std::vector<std::vector<int>> m_indexes;
      |         ^~~
a.cc: In constructor 'RangeIndex::RangeIndex(int)':
a.cc:4:17: error: 'm_indexes' was not declared in this scope
    4 |                 m_indexes.resize(n);
      |                 ^~~~~~~~~
a.cc: In member function 'int RangeIndex::getTrainsNum(int, int)':
a.cc:11:24: error: 'm_indexes' was not declared in this scope
   11 |                 return m_indexes[p - 1][q - 1];
      |                        ^~~~~~~~~
a.cc: In member function 'void RangeIndex::addTrains(int)':
a.cc:15:42: error: 'trains' was not declared in this scope; did you mean 'train'?
   15 |                 for (const auto &train : trains) {
      |                                          ^~~~~~
      |                                          train
a.cc: In member function 'void RangeIndex::addTrain(int, int)':
a.cc:25:68: error: 'm_indexes' was not declared in this scope
   25 |                         for (int j = (r - 1); j < static_cast<int>(m_indexes.size()); ++j) {
      |                                                                    ^~~~~~~~~
a.cc: At global scope:
a.cc:32:43: error: 'vector' in namespace 'std' does not name a template type
   32 | void outputResult(const int n, const std::vector<std::pair<int, int>> &trains,
      |                                           ^~~~~~
a.cc:32:38: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
   32 | void outputResult(const int n, const std::vector<std::pair<int, int>> &trains,
      |                                      ^~~
a.cc:32:49: error: expected ',' or '...' before '<' token
   32 | void outputResult(const int n, const std::vector<std::pair<int, int>> &trains,
      |                                                 ^
a.cc: In function 'void outputResult(int, int)':
a.cc:35:25: error: 'trains' was not declared in this scope
   35 |         index.addTrains(trains);
      |                         ^~~~~~
a.cc:36:34: error: 'ranges' was not declared in this scope; did you mean 'range'?
   36 |         for (const auto &range : ranges) {
      |                                  ^~~~~~
      |                                  range
a.cc:37:22: error: 'cout' is not a member of 'std'
   37 |                 std::cout << index.getTrainsNum(range.first, range.second) << std::endl;
      |                      ^~~~
a.cc:1:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | class RangeIndex {
a.cc:37:84: error: 'endl' is not a member of 'std'
   37 |                 std::cout << index.getTrainsNum(range.first, range.second) << std::endl;
      |                                                                                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | class RangeIndex {
a.cc: In function 'int main()':
a.cc:43:14: error: 'cin' is not a member of 'std'
   43 |         std::cin >> n >> m >> q;
      |              ^~~
a.cc:43:14: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:14: error: 'vector' is not a member of 'std'
   44 |         std::vector<std::pair<int, int>> trains(m);
      |              ^~~~~~
a.cc:44:14: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:44:26: error: 'pair' is not a member of 'std'
   44 |         std::vector<std::pair<int, int>> trains(m);
      |                          ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | class RangeIndex {
a.cc:44:31: error: expected primary-expression before 'int'
   44 |         std::vector<std::pair<int, int>> trains(m);
      |                               ^~~
a.cc:47:22: error: 'cin' is not a member of 'std'
   47 |                 std::cin >> l >> r;
      |                      ^~~
a.cc:47:22: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:48:17: error: 'trains' was not declared in this scope
   48 |                 trains[i] = std::make_pair(l, r);
      |                 ^~~~~~
a.cc:48:34: error: 'make_pair' is not a member of 'std'
   48 |                 trains[i] = std::make_pair(l, r);
      |                                  ^~~~~~~~~
a.cc:48:34: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:50:14: error: 'vector' is not a member of 'std'
   50 |         std::vector<std::pair<int, int>> ranges(q);
      |              ^~~~~~
a.cc:50:14: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:50:26: error: 'pair' is not a member of 'std'
   50 |         std::vector<std::pair<int, int>> ranges(q);
      |                          ^~~~
a.cc:50:26: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:50:31: error: expected primary-expression before 'int'
   50 |         std::vector<std::pair<int, int>> ranges(q);
      |                               ^~~
a.cc:53:22: error: 'cin' is not a member of 'std'
   53 |                 std::cin >> l >> r;
      |                      ^~~
a.cc:53:22: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:54:17: error: 'ranges' was not declared in this scope
   54 |                 ranges[i] = std::make_pair(l, r);
      |                 ^~~~~~
a.cc:54:34: error: 'make_pair' is not a member of 'std'
   54 |                 ranges[i] = std::make_pair(l, r);
      |                                  ^~~~~~~~~
a.cc:54:34: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:56:25: error: 'trains' was not declared in this scope
   56 |         outputResult(n, trains, ranges);
      |                         ^~~~~~
a.cc:56:33: error: 'ranges' was not declared in this scope
   56 |         outputResult(n, trains, ranges);
      |                                 ^~~~~~