Language: C++

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
struct Node{
	Node *lp,*rp;
	vector<T> vx,vy;
	int depth;
	P val;
	Node(){}
	Node(vector<T> vx,vector<T> vy,int d):lp(NULL),rp(NULL),vx(vx),vy(vy),depth(d){}
};
Node *root;
vector<int> ans;
map<P,int> m;
bool cmp_y(T a, T b){
	return a.fi.sec < b.fi.sec;
}
int tmp[500100];
//Node pool[1000100];
int cnt = 0;
Node *mynew(vector<T> vx,vector<T> vy,int d){
	pool[cnt++]=Node(vx,vy,d);
	return &pool[cnt-1];
}
void build(Node* &v,vector<T> vx,vector<T> vy,int d){
	int size = vx.size();
	int half = size/2;
	if(size==0)return;
	v = new Node(vx,vy,d);
	if(d%2==0){
		v->val = vx[half].fi;
		if(size==1)return;
		for(int i=0;i<size;i++){
			tmp[vx[i].sec]=i;
			vx[i].sec = i;
		}
		for(int i=0;i<size;i++)vy[i].sec=tmp[vy[i].sec];
		int border = vx[half].fi.fi;
		vector<T> lx,ly,rx,ry;
		for(int i=0;i<size;i++){
			if(vx[i].fi.fi<border)lx.pb(vx[i]);
			else rx.pb(vx[i]);
			if(vy[i].fi.fi<border)ly.pb(vy[i]);
			else ry.pb(vy[i]);
		}
		build(v->lp,lx,ly,d+1);
		build(v->rp,rx,ry,d+1);
	}else{
		v->val = vy[half].fi;
		if(size==1)return;
		for(int i=0;i<size;i++){
			tmp[vy[i].sec]=i;
			vy[i].sec = i;
		}
		for(int i=0;i<size;i++)vx[i].sec=tmp[vx[i].sec];
		int border = vy[half].fi.sec;
		vector<T> lx,ly,rx,ry;
		for(int i=0;i<size;i++){
			if(vx[i].fi.sec<border)lx.pb(vx[i]);
			else rx.pb(vx[i]);
			if(vy[i].fi.sec<border)ly.pb(vy[i]);
			else ry.pb(vy[i]);
		}
		build(v->lp,lx,ly,d+1);
		build(v->rp,rx,ry,d+1);
	}
	return;
}
/*void show(Node *v){
	if(v==NULL)return;
	show(v->lp);
	printf("%d %d ",(v->val).fi,(v->val).sec);
	if(v->lp!=NULL)printf("lp %d %d ",(v->lp->val).fi,(v->lp->val).sec);
	else printf("NULL NULL ");
	if(v->rp!=NULL)printf("rp %d %d\n",(v->rp->val).fi,(v->rp->val).sec);
	else printf("NULL NULL\n");
	show(v->rp);
}*/
void print(Node *v){
	ans.pb(m[v->val]);
}
void report_subtree(Node* v){
	if(v==NULL)return;
	if(v->lp==NULL&&v->rp==NULL)print(v);
	else{
		report_subtree(v->lp);
		report_subtree(v->rp);
	}
}
void query(Node *v,int L,int R,int D,int U,int a,int b,int c,int d){
	if(L>R||D>U)return;
	if(v==NULL)return;
	//printf("query %d %d %d %d %d %d %d %d\n",L,R,D,U,a,b,c,d);
	if(v->lp==NULL&&v->rp==NULL){
		int x = (v->val).fi, y = (v->val).sec;
		if(a<=x&&x<=b&&c<=y&&y<=d)print(v);
	}else{
		int nL=L,nR=R,nD=D,nU=U;
		if((v->depth)%2==0)nR = min(nR,(v->val).fi-1);
		else nU = min(nU,(v->val).sec-1);
		if(nL>nR||nD>nU){}
		else if(a<=nL&&nR<=b&&c<=nD&&nU<=d)report_subtree(v->lp);
		else if(nR<a||b<nL||nU<c||d<nD){}
		else query(v->lp,nL,nR,nD,nU,a,b,c,d);
		nL=L,nR=R,nD=D,nU=U;
		if((v->depth)%2==0)nL = max(nL,(v->val).fi);
		else nD = max(nD,(v->val).sec);
		if(nL>nR||nD>nU){}
		else if(a<=nL&&nR<=b&&c<=nD&&nU<=d)report_subtree(v->rp);
		else if(nR<a||b<nL||nU<c||d<nD){}
		else query(v->rp,nL,nR,nD,nU,a,b,c,d);
	}
}
int main(){
	int n,q;
	scanf("%d",&n);
	vector<T> px(n),py;
	for(int i=0;i<n;i++){
		scanf("%d %d",&px[i].fi.fi,&px[i].fi.sec);
		px[i].sec = i;
		m[px[i].fi]=i;
	}
	sort(all(px));
	py = px;
	sort(all(py),cmp_y);
	build(root,px,py,0);
	//show(root);
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		ans.clear();
		query(root,-INF,INF,-INF,INF,a,b,c,d);
		sort(all(ans));
		for(int i=0;i<ans.size();i++)printf("%d\n",ans[i]);
		printf("\n");
	}
	return 0;
}

Compiler output:
a.cc: In function 'Node* mynew(std::vector<std::pair<std::pair<int, int>, int> >, std::vector<std::pair<std::pair<int, int>, int> >, int)':
a.cc:55:9: error: 'pool' was not declared in this scope; did you mean 'powl'?
   55 |         pool[cnt++]=Node(vx,vy,d);
      |         ^~~~
      |         powl