Language: C++

import java.util.Scanner;
import java.io.*;

class Rmq{
    int segt[] = new int[(1<<21)*2];
    public int inp[] =new int[(1<<21)];
    int MAX_VALUE=2147483647;
    int min(int a,int b){return a<b?a:b;}
    int max(int a,int b){return a>b?a:b;}
    void update(int value,int pos,int n){
	int index=n-1+pos;
	segt[index]=value;//[pos,pos]
	while(index>0){
	    index=(index-1)/2;
	    segt[index]=min(segt[index*2+1],segt[index*2+2]);
	}
    }
    int query(int l,int r,int now,int ql,int qr){
	if (l == ql && r == qr){
	    return segt[now];
	}
	int midr=(l+r)/2,midl=midr+1;
	int ret=MAX_VALUE;
	if (ql <= midr)ret=min(ret,query(l,midr,now*2+1,ql,min(qr,midr)));
	if (midl <= qr)ret=min(ret,query(midl,r,now*2+2,max(midl,ql),qr));
	return ret;
    }

    public void init(int r,int c,int lim){
	boolean isrowmajor=r<=c;
	for(int i=0;i<lim;i++){
	    segt[i]=MAX_VALUE;
	}
	if (isrowmajor){
	    for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
		    update(inp[i*c+j],i*c+j,lim);
		}
	    }
	}else {
	    for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
		    update(inp[i+j*r],i+j*r,lim);
		}
	    }
	}
    }
    int searchmin(int r1,int c1,int r2,int c2,int r,int c,int lim){
	boolean isrowmajor = r<=c;  
	int ret=MAX_VALUE;
	lim--;
	if (isrowmajor){
	    for(int i=r1;i<=r2;i++){
		ret=min(ret,query(0,lim,0,i*c+c1,i*c+c2));
	    }
	}else {
	    for(int j=c1;j<=c2;j++){
		ret=min(ret,query(0,lim,0,j*r+r1,j*r+r2));
	    }
	}
	return ret;
    }    

}

class Main{
    void run(){
	Scanner in = new Scanner(System.in);
	//System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
	int r,c,q;
	Rmq rmq=new Rmq();
	while(true){
	    r=Integer.parseInt(in.next());
	    c=Integer.parseInt(in.next());
	    q=Integer.parseInt(in.next());
	    if (r == 0)break;
	    int lim=1;
	    boolean isrowmajor = r<=c;
	    while(true){
		if (lim >= r*c)break;
		lim*=2;
	    }
	    if (isrowmajor){
		for(int i=0;i<r;i++){
		    for(int j=0;j<c;j++){
			rmq.inp[i*c+j]=Integer.parseInt(in.next());
		    }
		}
	    }else {
		for(int i=0;i<r;i++){
		    for(int j=0;j<c;j++){
			rmq.inp[i+j*r]=Integer.parseInt(in.next());
		    }
		}
	    }
	    rmq.init(r,c,lim);
	    for(int i=0;i<q;i++){
		int r1,r2,c1,c2;
		r1=Integer.parseInt(in.next());
		c1=Integer.parseInt(in.next());
		r2=Integer.parseInt(in.next());
		c2=Integer.parseInt(in.next());
		System.out.println(rmq.searchmin(r1,c1,r2,c2,r,c,lim));
	    }
	}
    }
    public static void main(String args[]){
	Main a = new Main();
	a.run();
    }
}

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.Scanner;
      | ^~~~~~
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 java.io.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:11: error: expected ':' before 'int'
    6 |     public int inp[] =new int[(1<<21)];
      |           ^~~~
      |           :
a.cc:29:11: error: expected ':' before 'void'
   29 |     public void init(int r,int c,int lim){
      |           ^~~~~
      |           :
a.cc:5:9: error: flexible array member 'Rmq::segt' not at end of 'class Rmq'
    5 |     int segt[] = new int[(1<<21)*2];
      |         ^~~~
a.cc:64:2: error: expected ';' after class definition
   64 | }
      |  ^
      |  ;
a.cc:5:9: error: initializer for flexible array member 'int Rmq::segt []'
    5 |     int segt[] = new int[(1<<21)*2];
      |         ^~~~
a.cc:6:16: error: initializer for flexible array member 'int Rmq::inp []'
    6 |     public int inp[] =new int[(1<<21)];
      |                ^~~
a.cc: In member function 'void Rmq::init(int, int, int)':
a.cc:30:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   30 |         boolean isrowmajor=r<=c;
      |         ^~~~~~~
      |         bool
a.cc:34:13: error: 'isrowmajor' was not declared in this scope
   34 |         if (isrowmajor){
      |             ^~~~~~~~~~
a.cc: In member function 'int Rmq::searchmin(int, int, int, int, int, int, int)':
a.cc:49:9: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   49 |         boolean isrowmajor = r<=c;
      |         ^~~~~~~
      |         bool
a.cc:52:13: error: 'isrowmajor' was not declared in this scope
   52 |         if (isrowmajor){
      |             ^~~~~~~~~~
a.cc: At global scope:
a.cc:107:11: error: expected ':' before 'static'
  107 |     public static void main(String args[]){
      |           ^~~~~~~
      |           :
a.cc:107:29: error: 'String' has not been declared
  107 |     public static void main(String args[]){
      |                             ^~~~~~
a.cc:111:2: error: expected ';' after class definition
  111 | }
      |  ^
      |  ;
a.cc: In member function 'void Main::run()':
a.cc:68:9: error: 'Scanner' was not declared in this scope
   68 |         Scanner in = new Scanner(System.in);
      |         ^~~~~~~
a.cc:73:15: error: 'Integer' was not declared in this scope
   73 |             r=Integer.parseInt(in.next());
      |               ^~~~~~~
a.cc:73:32: error: 'in' was not declared in this scope; did you mean 'int'?
   73 |             r=Integer.parseInt(in.next());
      |                                ^~
      |                                int
a.cc:78:13: error: 'boolean' was not declared in this scope; did you mean 'bool'?
   78 |             boolean isrowmajor = r<=c;
      |             ^~~~~~~
      |             bool
a.cc:83:17: error: 'isrowmajor' was not declared in this scope
   83 |             if (isrowmajor){
      |                 ^~~~~~~~~~
a.cc:103:17: error: 'System' was not declared in this scope
  103 |                 System.out.println(rmq.searchmin(r1,c1,r2,c2,r,c,lim));
      |                 ^~~~~~
a.cc: In static member function 'static void Main::main(int*)':
a.cc:108:18: error: conversion from 'Main*' to non-scalar type 'Main' requested
  108 |         Main a = new Main();
      |                  ^~~~~~~~~~