Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

struct Point{
    int i, x, y;

    Point(){}

    Point(int i, int x, int y):x(x),y(y),i(i) {}

    void print(){
        cout << i << endl;
    }
};
bool lessX(const Point &p1, const Point &p2){ return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2){ return p1.y < p2.y; }
bool lessI(const Point &p1, const Point &p2){ return p1.i < p2.i; }

struct Rect{
    int sx, sy, tx, ty;
    Rect(int sx, int sy, int tx, int ty):sx(sx), sy(sy),tx(tx),ty(ty){}

    bool cover(Point &p){
        return (sx <= p.x && tx >= p.x && sy <= p.y && ty >= p.y);
    }
};

class Node{
public:
    Node *ld, *ru;
    Point *p;
};

const int MAX_N = 1000000;
Node T[MAX_N];
int number;

class KdTree{
private:
    Node *root;
public:
    KdTree(Point *pts, int n){
        sort(pts, pts + n, lessX);
        int l = 0, r = n, m = (l + r) / 2;
        number = 0;
        T[number].p = &pts[m];
        root = T;

        build(root, pts, 0, m, m + 1, r, 1);

    }

    void build(Node *parent, Point *pts, int ll, int lr, int rl, int rr, int depth) {
        bool (*c)(const Point &p1, const Point &p2) =  depth % 2 == 0 ? lessX : lessY;

        // left or down
        if (ll < lr) {
            sort(pts+ll, pts+lr, c);
            int lm = (ll + lr) / 2;
            T[++number].p = &pts[lm];
            parent->ld = &T[number];
            build(parent->ld, pts, ll, lm, lm + 1, lr, depth + 1);
        }

        // right or up
        if (rl < rr) {
            sort(pts+rl, pts+rr, c);
            int rm = (rl + rr) / 2;
            T[++number].p = &pts[rm];
            parent->ru = &T[number];
            build(parent->ru, pts, rl, rm, rm + 1, rr, depth + 1);
        }
    }

    void queryRect(Rect &rect, vector<Point> &inPts) {
        queryRectRecur(rect, root, 0, inPts);

    }

    void queryRectRecur(Rect rect, Node *node, int depth, vector<Point> &inPts) {
        if (node == nullptr) {
            return;
        }

        if(rect.cover(node->p[0])) inPts.push_back(node->p[0]);

        if (depth % 2 == 0) {
            if(rect.tx >= node->p[0].x) queryRectRecur(rect, node->ru, depth+1, inPts);
            if(rect.sx <= node->p[0].x) queryRectRecur(rect, node->ld, depth+1, inPts);
        }
        else{
            if(rect.ty >= node->p[0].y) queryRectRecur(rect, node->ru, depth+1, inPts);
            if(rect.sy <= node->p[0].y) queryRectRecur(rect, node->ld, depth+1, inPts);
        }
    }

};

int main() {
    int n;
    cin >> n;
    Point pts[n];
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        pts[i] = Point(i, x, y);
    }

    KdTree kdTree(pts, n);

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int sx, tx, sy, ty;
        cin >> sx >> tx >> sy >> ty;
        Rect rect(sx, sy, tx, ty);

        vector<Point> inPts;
        kdTree.queryRect(rect, inPts);


        sort(inPts.begin(), inPts.end(), lessI);
        for (Point p : inPts) {
            p.print();
        }
        cout << endl;
    }

    return 0;
}


Compiler output:
a.cc:77:32: error: 'vector' has not been declared
   77 |     void queryRect(Rect &rect, vector<Point> &inPts) {
      |                                ^~~~~~
a.cc:77:38: error: expected ',' or '...' before '<' token
   77 |     void queryRect(Rect &rect, vector<Point> &inPts) {
      |                                      ^
a.cc:82:59: error: 'vector' has not been declared
   82 |     void queryRectRecur(Rect rect, Node *node, int depth, vector<Point> &inPts) {
      |                                                           ^~~~~~
a.cc:82:65: error: expected ',' or '...' before '<' token
   82 |     void queryRectRecur(Rect rect, Node *node, int depth, vector<Point> &inPts) {
      |                                                                 ^
a.cc: In member function 'void KdTree::queryRect(Rect&, int)':
a.cc:78:39: error: 'inPts' was not declared in this scope; did you mean 'int'?
   78 |         queryRectRecur(rect, root, 0, inPts);
      |                                       ^~~~~
      |                                       int
a.cc: In member function 'void KdTree::queryRectRecur(Rect, Node*, int, int)':
a.cc:87:36: error: 'inPts' was not declared in this scope; did you mean 'int'?
   87 |         if(rect.cover(node->p[0])) inPts.push_back(node->p[0]);
      |                                    ^~~~~
      |                                    int
a.cc:90:81: error: 'inPts' was not declared in this scope; did you mean 'int'?
   90 |             if(rect.tx >= node->p[0].x) queryRectRecur(rect, node->ru, depth+1, inPts);
      |                                                                                 ^~~~~
      |                                                                                 int
a.cc:91:81: error: 'inPts' was not declared in this scope; did you mean 'int'?
   91 |             if(rect.sx <= node->p[0].x) queryRectRecur(rect, node->ld, depth+1, inPts);
      |                                                                                 ^~~~~
      |                                                                                 int
a.cc:94:81: error: 'inPts' was not declared in this scope; did you mean 'int'?
   94 |             if(rect.ty >= node->p[0].y) queryRectRecur(rect, node->ru, depth+1, inPts);
      |                                                                                 ^~~~~
      |                                                                                 int
a.cc:95:81: error: 'inPts' was not declared in this scope; did you mean 'int'?
   95 |             if(rect.sy <= node->p[0].y) queryRectRecur(rect, node->ld, depth+1, inPts);
      |                                                                                 ^~~~~
      |                                                                                 int
a.cc: In function 'int main()':
a.cc:120:9: error: 'vector' was not declared in this scope
  120 |         vector<Point> inPts;
      |         ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | 
a.cc:120:21: error: expected primary-expression before '>' token
  120 |         vector<Point> inPts;
      |                     ^
a.cc:120:23: error: 'inPts' was not declared in this scope; did you mean 'int'?
  120 |         vector<Point> inPts;
      |                       ^~~~~
      |                       int