Language: C++

#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)n; i++)

//FILE *in = freopen("input.txt", "r", stdin);

struct BIT{
	vector<int> bit;
	int size;
	
	BIT(int n){
		size=n;bit=vector<int>(n+1);
	}
	
	void add(int i,int x){
		i+=1;
		while(i<=size)bit[i]+=x,i+=i&-i;
	}

	int sum(int i){
		int s=0;
		while(i>0)s+=bit[i],i-=i&-i;
		return s;
	}
};

struct BIT2D{
	vector<BIT> bit;
	BIT2D(int x,int y):bit(x+1,BIT(y)){};
	
	void add(int x, int y, int v){
		x++;
		while(x < (int)bit.size()){
			bit[x].add(y, v);
			x += x & -x;
		}
	}

	int sum(int x,int y){
		int s = 0;
		while(x > 0){
			s += bit[x].sum(y);
			x -= x & -x;
		}
		return s;
	}
};

int n, m;
int data[5000][2];
int query[500000][4];
map<int,int> xmap;
map<int,int> ymap;

int xmax, ymax;
vector<int> xs;
vector<int> ys;

void input() {
	scanf("%d%d", &n, &m);
	rep(i, n) {
		scanf("%d%d", &data[i][0], &data[i][1]);
		xs.push_back(data[i][0]);
		ys.push_back(data[i][1]);
	}
	rep(i,m) {
		scanf("%d%d%d%d", &query[i][0], &query[i][1], &query[i][2], &query[i][3]);
		xs.push_back(query[i][0]);
		ys.push_back(query[i][1]);
		xs.push_back(query[i][2]);
		ys.push_back(query[i][3]);
	}

	sort(xs.begin(), xs.end());
	sort(ys.begin(), ys.end());

	{
		auto eiter = unique(xs.begin(), xs.end());
		auto iter = xs.begin();
		int i = 0;
		for(i = 0; iter != eiter; iter++, i++) {
			xmap[*iter] = i;
		}
		xmax = i;
	}
	{
		auto eiter = unique(ys.begin(), ys.end());
		auto iter = ys.begin();
		int i = 0;
		for(i = 0; iter != eiter; iter++, i++) {
			ymap[*iter] = i;
		}
		ymax = i;
	}
}

void process() {
	BIT2D qq(xmax, ymax);

	rep(i, n) {
		qq.add(xmap[data[i][0]], ymap[data[i][1]], 1);
	}

	rep(i, m) {
		int sumxy = qq.sum(xmap[query[i][2]] + 1, ymap[query[i][3]] + 1);
		int sumxyy = qq.sum(xmap[query[i][2]] + 1, ymap[query[i][1]]);
		int sumxxy = qq.sum(xmap[query[i][0]], ymap[query[i][3]] + 1);
		int sumxxyy = qq.sum(xmap[query[i][0]], ymap[query[i][1]]);
		printf("%d\n", sumxy - sumxyy - sumxxy + sumxxyy);
	}
}

void output() {
}

int main() {
	input();
	process();
	output();
	return 0;
}

Compiler output:
a.cc: In function 'void input()':
a.cc:67:32: error: reference to 'data' is ambiguous
   67 |                 scanf("%d%d", &data[i][0], &data[i][1]);
      |                                ^~~~
In file included from /usr/include/c++/14/map:65,
                 from a.cc:2:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~
a.cc:67:45: error: reference to 'data' is ambiguous
   67 |                 scanf("%d%d", &data[i][0], &data[i][1]);
      |                                             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~
a.cc:68:30: error: reference to 'data' is ambiguous
   68 |                 xs.push_back(data[i][0]);
      |                              ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~
a.cc:69:30: error: reference to 'data' is ambiguous
   69 |                 ys.push_back(data[i][1]);
      |                              ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~
a.cc: In function 'void process()':
a.cc:106:29: error: reference to 'data' is ambiguous
  106 |                 qq.add(xmap[data[i][0]], ymap[data[i][1]], 1);
      |                             ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~
a.cc:106:47: error: reference to 'data' is ambiguous
  106 |                 qq.add(xmap[data[i][0]], ymap[data[i][1]], 1);
      |                                               ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:55:5: note:                 'int data [5000][2]'
   55 | int data[5000][2];
      |     ^~~~