Language: C++

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

struct Point {
    int x, y;
    int index;
};
class RangeTree {
    class Node {
        Node parent;
        Node left, right;
        int left_x, right_x;
        int[] ys;
        override string toString() const {
            return format("([%s,%s] -> %s)", left_x, right_x, ys);
        }
    }
    Point[] P;
    Node root;
    Node construct(int[] ps) {
        auto n = new Node;
        n.left_x = P[ps.front].x;
        n.right_x = P[ps.back].x;
        if(ps.length <= 1024) {
            n.ys = ps.sort!((i, j)=>(P[i].y < P[j].y)).array;
            return n;
        }
        auto l = construct(ps[0 .. $ / 2]);
        auto r = construct(ps[$ / 2 .. $]);
        l.parent = n;
        r.parent = n;
        n.left = l;
        n.right = r;
        auto li = 0, ri = 0;
        while (true) {
            if (li >= l.ys.length && ri >= r.ys.length) break;
            if (li >= l.ys.length) n.ys ~= r.ys[ri++];
            else if (ri >= r.ys.length) n.ys ~= l.ys[li++];
            else {
                n.ys ~= (P[l.ys[li]].y < P[r.ys[ri]].y ? l.ys[li++] : r.ys[ri++]);
            }
        }
        return n;
    }
    this(Point[] ps) {
        this.P = ps.dup;
        auto ys = iota(0, ps.size, 1).array.sort!((i, j) => P[i].x < P[j].x).array;
        this.root = construct(ys);
    }

    /* (sx <= x <= gx && sy <= y <= gy)????????§??????(x, y)??§?±?esult???????????\??§??????. ??¢????????¢?????????????±???¨??¢???*/
    int[] query(int sx, int sy, int gx, int gy) {
        int[] result;
        void f(Node cur_root) {
            if (gx < cur_root.left_x || cur_root.right_x < sx) {
                // do nothing
            } else if (sx <= cur_root.left_x && cur_root.right_x <= gx) {
                int[] ys = cur_root.ys;
                result ~= ys.map!((i)=>tuple(P[i].y, i)).assumeSorted.upperBound(tuple(sy, 0)).lowerBound(tuple(gy + 1, 0)).map!((x)=>x[1]).array;
                //result ~= ys.assumeSorted!((i, j) => (P[i].y < P[j].y)).upperBound(sy).lowerBound(gy + 1).array;
            } else {
                if(cur_root.left is null || cur_root.right is null) {
                    foreach (i; cur_root.ys.map!((i)=>tuple(P[i].y, i)).assumeSorted.upperBound(tuple(sy, 0)).lowerBound(tuple(gy + 1, 0)).map!((x)=>x[1])) {
                        auto p = P[i];
                        if (sx <= p.x && p.x <= gx && sy <= p.y && p.y <= gy) {
                            result ~= i;
                        }
                    }
                } else {
                    f(cur_root.left);
                    f(cur_root.right);
                }
            }
        }
        f(root);
        return result;
    }
}

void main() {
    int N = readln.chomp.to!int;
    auto P = new Point[N];
    foreach (int i; 0 .. N) {
        readf("%s %s\n", &P[i].x, &P[i].y);
        P[i].index = i;
    }
    auto tree = new RangeTree(P);
    int Q = readln.chomp.to!int;
    foreach (_; 0 .. Q) {
        int sx, sy, gx, gy; readf("%s %s %s %s\n", &sx, &gx, &sy, &gy);
        auto result = tree.query(sx, sy, gx, gy);
        sort(result);
        foreach (r; result) {
            writeln(r);
        }
        writeln("");
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import std.algorithm;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.array;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.ascii;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.container;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import std.conv;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import std.math;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import std.numeric;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import std.range;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: 'import' does not name a type
    9 | import std.stdio;
      | ^~~~~~
a.cc:9:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'import' does not name a type
   10 | import std.string;
      | ^~~~~~
a.cc:10:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:11:1: error: 'import' does not name a type
   11 | import std.typecons;
      | ^~~~~~
a.cc:11:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:13:6: error: variable or field 'log' declared void
   13 | void log(A...)(A arg) {
      |      ^~~
a.cc:13:10: error: 'A' was not declared in this scope
   13 | void log(A...)(A arg) {
      |          ^
a.cc:16:10: error: 'T' was not declared in this scope
   16 | int size(T)(in T s) {
      |          ^
a.cc:26:14: error: field 'parent' has incomplete type 'RangeTree::Node'
   26 |         Node parent;
      |              ^~~~~~
a.cc:25:11: note: definition of 'class RangeTree::Node' is not complete until the closing brace
   25 |     class Node {
      |           ^~~~
a.cc:27:14: error: field 'left' has incomplete type 'RangeTree::Node'
   27 |         Node left, right;
      |              ^~~~
a.cc:25:11: note: definition of 'class RangeTree::Node' is not complete until the closing brace
   25 |     class Node {
      |           ^~~~
a.cc:27:20: error: field 'right' has incomplete type 'RangeTree::Node'
   27 |         Node left, right;
      |                    ^~~~~
a.cc:25:11: note: definition of 'class RangeTree::Node' is not complete until the closing brace
   25 |     class Node {
      |           ^~~~
a.cc:29:12: error: expected unqualified-id before '[' token
   29 |         int[] ys;
      |            ^
a.cc:30:9: error: 'override' does not name a type
   30 |         override string toString() const {
      |         ^~~~~~~~
a.cc:34:11: error: expected ';' at end of member declaration
   34 |     Point[] P;
      |           ^
      |            ;
a.cc:34:13: error: 'P' does not name a type
   34 |     Point[] P;
      |             ^
a.cc:36:26: error: expected ',' or '...' before 'ps'
   36 |     Node construct(int[] ps) {
      |                          ^~
a.cc:61:5: error: expected unqualified-id before 'this'
   61 |     this(Point[] ps) {
      |     ^~~~
a.cc:68:8: error: expected unqualified-id before '[' token
   68 |     int[] query(int sx, int sy, int gx, int gy) {
      |        ^
a.cc:34:5: error: flexible array member 'RangeTree::Point' not at end of 'class RangeTree'
   34 |     Point[] P;
      |     ^~~~~
a.cc:94:2: error: expected ';' after class definition
   94 | }
      |  ^
      |  ;
a.cc: In member function 'RangeTree::Node RangeTree::construct(int*)':
a.cc:38:11: error: request for member 'left_x' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   38 |         n.left_x = P[ps.front].x;
      |           ^~~~~~
a.cc:38:20: error: 'P' was not declared in this scope
   38 |         n.left_x = P[ps.front].x;
      |                    ^
a.cc:38:22: error: 'ps' was not declared in this scope
   38 |         n.left_x = P[ps.front].x;
      |                      ^~
a.cc:39:11: error: request for member 'right_x' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   39 |         n.right_x = P[ps.back].x;
      |           ^~~~~~~
a.cc:41:15: error: request for member 'ys' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   41 |             n.ys = ps.sort!((i, j)=>(P[i].y < P[j].y)).array;
      |               ^~
a.cc:42:20: error: could not convert 'n' from 'RangeTree::Node*' to 'RangeTree::Node'
   42 |             return n;
      |                    ^
      |                    |
      |                    RangeTree::Node*
a.cc:44:34: error: expected unqualified-id before '.' token
   44 |         auto l = construct(ps[0 .. $ / 2]);
      |                                  ^
a.cc:45:31: error: '$' was not declared in this scope
   45 |         auto r = construct(ps[$ / 2 .. $]);
      |                               ^
a.cc:45:38: error: expected unqualified-id before '.' token
   45 |         auto r = construct(ps[$ / 2 .. $]);
      |                                      ^
a.cc:48:11: error: request for member 'left' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   48 |         n.left = l;
      |           ^~~~
a.cc:49:11: error: request for member 'right' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   49 |         n.right = r;
      |           ^~~~~
a.cc:53:38: error: request for member 'ys' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   53 |             if (li >= l.ys.length) n.ys ~= r.ys[ri++];
      |                                      ^~
a.cc:54:43: error: request for member 'ys' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   54 |             else if (ri >= r.ys.length) n.ys ~= l.ys[li++];
      |                                           ^~
a.cc:56:19: error: request for member 'ys' in 'n', which is of pointer type 'RangeTree::Node*' (maybe you meant to use '->' ?)
   56 |                 n.ys ~= (P[l.ys[li]].y < P[r.ys[ri]].y ? l.ys[li++] : r.ys[ri++]);
      |                   ^~
a.cc:59:16: error: could not convert 'n' from 'RangeTree::Node*' to 'RangeTree::Node'
   59 |         return n;
      |                ^
      |                |
      |                RangeTree::Node*
a.cc: At global scope:
a.cc:96:1: error: '::main' must return 'int'
   96 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:97:13: error: 'readln' was not declared in this scope
   97 |     int N = readln.chomp.to!int;
      |             ^~~~~~
a.cc:99:14: error: expected primary-expression before 'int'
   99 |     foreach (int i; 0 .. N) {
      |              ^~~
a.cc:99:24: error: expected unqualified-id before '.' token
   99 |     foreach (int i; 0 .. N) {
      |                        ^
a.cc:103:32: error: no matching function for call to 'RangeTree::RangeTree(Point*&)'
  103 |     auto tree = new RangeTree(P);
      |                                ^
a.cc:24:7: note: candidate: 'RangeTree::RangeTree()'
   24 | class RangeTree {
      |       ^~~~~~~~~
a.cc:24:7: note:   candidate expects 0 arguments, 1 provided
a.cc:24:7: note: candidate: 'constexpr RangeTree::RangeTree(const RangeTree&)'
a.cc:24:7: note:   no known conversion for argument 1 from 'Point*' to 'const RangeTree&'
a.cc:24:7: note: candidate: 'constexpr RangeTree::RangeTree(RangeTree&&)'
a.cc:24:7: note:   no known conversion for argument 1 from 'Point*' to 'RangeTree&&'
a.cc:105:14: error: '_' was not declared in this scope
  105 |     foreach (_; 0 .. Q) {
      |              ^
a.cc:105:20: error: expected unqualified-id before '.' token
  105 |     foreach (_; 0 .. Q) {
      |                    ^