Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>

typedef struct node{
	int x;
	int y;
	int depth;
	int id;
	node *right;
	node *left;
} node;

node *nil;
std::vector<int> ans;

void init_node(node *n, int x, int y, int id){
	n->left = nil;
	n->right = nil;
	n->x = x;
	n->y = y;
	n->id = id;
}

void linkage(node* child, node* parent){
	int parent_num, child_num;
	if (parent->depth % 2 == 0){
		parent_num = parent->x;
		child_num = child->x;
	}
	else{
		parent_num = parent->y;
		child_num = child->y;
	}	

	if(child_num >= parent_num){
		if(parent->right != nil){
			linkage(child, parent->right);
		}
		else{
			parent->right = child;
			child->depth = parent->depth + 1;
		}
	}
	else{
		if(parent->left != nil){
			linkage(child, parent->left);
		}
		else{
			parent->left = child;
			child->depth = parent->depth+1;
		}
	}
}

void make_node(int x, int y, int id, node *new_node, node* root){
	init_node(new_node, x, y, id);
	linkage(new_node, root);
}

void search(node *n, int x_l, int x_h, int y_l, int y_h){
	int x = n->x;
	int y = n->y;
	
	if (x_l <= x && x <= x_h && y_l <= y && y <= y_h) ans.push_back(n->id);
	
	if (n->depth % 2 == 0){
		if (n->left != nil && x_l <= x) search(n->left, x_l, x_h, y_l, y_h, ans);
		if (n->right != nil && x <= x_h) search(n->right, x_l, x_h, y_l, y_h, ans);
	}
	
	else{
		if (n->left != nil && y_l <= y) search(n->left, x_l, x_h, y_l, y_h, ans);
		if (n->right != nil && y <= y_h) search(n->right, x_l, x_h, y_l, y_h, ans);
	}
	
}

void search_from_root(node *root, int x_l, int x_h, int y_l, int y_h){
	std::vector<int> ans;
	search(root, x_l, x_h, y_l, y_h, ans);
	sort(ans.begin(), ans.end());
	for (int i=0; i<ans.size(); i++) printf("%d\n", ans[i]);
	printf("\n");
	ans.clear()
}

int main(void){
	int n, q, x, y;
	node root;
	node *new_node;
	scanf("%d", &n);
	scanf("%d %d", &x, &y);
	init_node(&root, x, y, 0);
	root.depth = 0;

	for(int i=0; i<n-1;i++){
		scanf("%d %d", &x, &y);
		new_node = new node;
		make_node(x, y, i+1, new_node, &root);
	}
	
	scanf("%d", &q);
	int x_low, x_high, y_low, y_high;
	for (int i=0;i<q;i++){
		scanf("%d %d %d %d", &x_low, &x_high, &y_low, &y_high);
		search_from_root(&root, x_low, x_high, y_low, y_high);
	}
}

Compiler output:
a.cc: In function 'void search(node*, int, int, int, int)':
a.cc:68:55: error: no matching function for call to 'search(node*&, int&, int&, int&, int&, std::vector<int>&)'
   68 |                 if (n->left != nil && x_l <= x) search(n->left, x_l, x_h, y_l, y_h, ans);
      |                                                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 6 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   candidate expects 4 arguments, 6 provided
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 6 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15:
/usr/include/c++/14/pstl/execution_defs.h: In substitution of 'template<class _ExecPolicy, class _Tp> using __pstl::__internal::__enable_if_execution_policy = typename std::enable_if<__pstl::execution::v1::is_execution_policy<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type>::value, _Tp>::type [with _ExecPolicy = node*&; _Tp = int]':
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1:   required by substitution of 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate) [with _ExecutionPolicy = node*&; _ForwardIterator1 = int; _ForwardIterator2 = int; _BinaryPredicate = std::vector<int>]'
a.cc:68:41:   required from here
   68 |                 if (n->left != nil && x_l <= x) search(n->left, x_l, x_h, y_l, y_h, ans);
      |                                                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/execution_defs.h:82:7: error: no type named 'type' in 'struct std::enable_if<false, int>'
   82 | using __enable_if_execution_policy =
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note:   candidate expects 5 arguments, 6 provided
a.cc:61:6: note: candidate: 'void search(node*, int, int, int, int)'
   61 | void search(node *n, int x_l, int x_h, int y_l, int y_h){
      |      ^~~~~~
a.cc:61:6: note:   candidate expects 5 arguments, 6 provided
a.cc:69:56: error: no matching function for call to 'search(node*&, int&, int&, int&, int&, std::vector<int>&)'
   69 |                 if (n->right != nil && x <= x_h) search(n->right, x_l, x_h, y_l, y_h, ans);
      |                                                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 6 provided
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   candidate expects 4 arguments, 6 provided
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 6 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   template argument deduction/substitution failed:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note:   candidate expects 5 arguments, 6 provided
a.cc:61:6: note: candidate: 'void search(node*, int, int, int, int)'
   61 | void search(node *n, int x_l, int x_h, int y_l, int y_h){
      |      ^~~~~~
a.cc:61:6: note:   candidate expects 5 arguments, 6 provided
a.cc:73:55: error: no matching function for call to 'search(node*&, int&, int&, int&, int&, std::vector<int>&)'
   73 |                 if (n->left != nil && y_l <= y) search(n->left, x_l, x_h, y_l, y_h, ans);
      |                                                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 6 provided
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   candidate expects 4 arguments, 6 provided
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 6 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   template argument deduction/substitution failed:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:11