Language: C++


import java.util.*;
import java.lang.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	int MAX = 10005;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt(), r = sc.nextInt();
			if ((n|r) == 0) break;
			E[] G = new E[MAX];
			for (int i = 0; i < MAX;i++) G[i] = new E();
			for (int i=0;i<n;i++) {
				int x1 = sc.nextInt()+1, y1 = sc.nextInt()+1, x2 = sc.nextInt()+1, y2 = sc.nextInt()+1;
				G[y1].add(new P(x1, x2, true));
				G[y2].add(new P(x1, x2, false));
			}
			int a = 0, l = 0, t = 1, minx = MAX, maxx = 0;
			int[][] area = new int[2][MAX];
			for (E e: G) {
				fill(area[t], 0);
				for (P p: e) {
					area[t][p.x1] += p.c ? 1: -1; area[t][p.x2] += p.c ? -1 : 1;
					minx = min(minx, p.x1); maxx = max(maxx, p.x2);
				}
				for (int i = minx; i <= maxx; i++) {
					area[t][i] += area[t][i-1] + area[1-t][i] - area[1-t][i-1];
					if (area[t][i] > 0) a++;
					if (((area[t][i] | area[1-t][i]) != 0 ) && area[t][i] * area[1-t][i] == 0) l++;
					if (((area[t][i] | area[t][i-1]) != 0 ) && area[t][i] * area[t][i-1] == 0) l++;
				}
//				debug(area[t]);
				t ^= 1;
			}
			System.out.println(a);
			if (r == 2) System.out.println(l);
		}
	}
	
	class E extends ArrayList<P>{};
	
	class P {
		int x1, x2; boolean c;
		P(int x1, int x2, boolean c) {
			this.x1 = x1;
			this.x2 = x2;
			this.c = c;
		}
	}
	
	void debug(Object... os) {
		System.out.println(deepToString(os));
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		new Main().run();
	}
}

Compiler output:
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.*;
      | ^~~~~~
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 java.lang.*;
      | ^~~~~~
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 java.io.*;
      | ^~~~~~
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 static java.util.Arrays.*;
      | ^~~~~~
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 static java.util.Collections.*;
      | ^~~~~~
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 static java.lang.Math.*;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:47:17: error: field 'extends' has incomplete type 'E'
   47 |         class E extends ArrayList<P>{};
      |                 ^~~~~~~
a.cc:47:15: note: forward declaration of 'class E'
   47 |         class E extends ArrayList<P>{};
      |               ^
a.cc:47:17: error: expected ';' at end of member declaration
   47 |         class E extends ArrayList<P>{};
      |                 ^~~~~~~
      |                        ;
a.cc:47:25: error: 'ArrayList' does not name a type
   47 |         class E extends ArrayList<P>{};
      |                         ^~~~~~~~~
a.cc:50:29: error: 'boolean' does not name a type; did you mean 'bool'?
   50 |                 int x1, x2; boolean c;
      |                             ^~~~~~~
      |                             bool
a.cc:51:35: error: 'boolean' has not been declared
   51 |                 P(int x1, int x2, boolean c) {
      |                                   ^~~~~~~
a.cc:56:10: error: expected ';' after class definition
   56 |         }
      |          ^
      |          ;
a.cc:58:20: error: 'Object' has not been declared
   58 |         void debug(Object... os) {
      |                    ^~~~~~
a.cc:58:30: error: expansion pattern 'int' contains no parameter packs
   58 |         void debug(Object... os) {
      |                              ^~
a.cc:62:15: error: expected ':' before 'static'
   62 |         public static void main (String[] args) throws java.lang.Exception
      |               ^~~~~~~
      |               :
a.cc:62:34: error: 'String' has not been declared
   62 |         public static void main (String[] args) throws java.lang.Exception
      |                                  ^~~~~~
a.cc:62:43: error: expected ',' or '...' before 'args'
   62 |         public static void main (String[] args) throws java.lang.Exception
      |                                           ^~~~
a.cc:62:47: error: expected ';' at end of member declaration
   62 |         public static void main (String[] args) throws java.lang.Exception
      |                                               ^
      |                                                ;
a.cc:62:49: error: 'throws' does not name a type
   62 |         public static void main (String[] args) throws java.lang.Exception
      |                                                 ^~~~~~
a.cc:66:2: error: expected ';' after class definition
   66 | }
      |  ^
      |  ;
a.cc: In member function 'void Main::run()':
a.cc:14:17: error: 'Scanner' was not declared in this scope
   14 |                 Scanner sc = new Scanner(System.in);
      |                 ^~~~~~~
a.cc:16:33: error: 'sc' was not declared in this scope
   16 |                         int n = sc.nextInt(), r = sc.nextInt();
      |                                 ^~
a.cc:17:32: error: 'r' was not declared in this scope
   17 |                         if ((n|r) == 0) break;
      |                                ^
a.cc:18:26: error: structured binding declaration cannot have type 'E'
   18 |                         E[] G = new E[MAX];
      |                          ^~
a.cc:18:26: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:18:26: error: empty structured binding declaration
a.cc:18:29: error: expected initializer before 'G'
   18 |                         E[] G = new E[MAX];
      |                             ^
a.cc:19:54: error: 'G' was not declared in this scope
   19 |                         for (int i = 0; i < MAX;i++) G[i] = new E();
      |                                                      ^
a.cc:19:67: error: invalid use of incomplete type 'class E'
   19 |                         for (int i = 0; i < MAX;i++) G[i] = new E();
      |                                                                   ^
a.cc:47:15: note: forward declaration of 'class E'
   47 |         class E extends ArrayList<P>{};
      |               ^
a.cc:22:33: error: 'G' was not declared in this scope
   22 |                                 G[y1].add(new P(x1, x2, true));
      |                                 ^
a.cc:22:35: error: 'y1' was not declared in this scope; did you mean 'x1'?
   22 |                                 G[y1].add(new P(x1, x2, true));
      |                                   ^~
      |                                   x1
a.cc:22:53: error: 'x2' was not declared in this scope; did you mean 'x1'?
   22 |                                 G[y1].add(new P(x1, x2, true));
      |                                                     ^~
      |                                                     x1
a.cc:23:35: error: 'y2' was not declared in this scope
   23 |                                 G[y2].add(new P(x1, x2, false));
      |                                   ^~
a.cc:26:28: error: structured binding declaration cannot have type 'int'
   26 |                         int[][] area = new int[2][MAX];
      |                            ^~
a.cc:26:28: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:26:28: error: empty structured binding declaration
a.cc:26:30: error: expected initializer before '[' token
   26 |                         int[][] area = new int[2][MAX];
      |                              ^
a.cc:27:32: error: variable 'E e' has initializer but incomplete type
   27 |                         for (E e: G) {
      |                                ^
a.cc:27:35: error: 'G' was not declared in this scope
   27 |                         for (E e: G) {
      |                                   ^
a.cc:28:38: error: 'area' was not declared in this scope
   28 |                                 fill(area[t], 0);
      |                                      ^~~~
a.cc:28:33: error: 'fill' was not declared in this scope
   28 |                                 fill(area[t], 0);
      |                                 ^~~~
a.cc:30:51: error: 'int Main::P::x1' is private within this context
   30 |                                         area[t][p.x1] += p.c ? 1: -1; area[t][p.x2] += p.c ? -1 : 1;
      |                                                   ^~
a.cc:50:21: note: declared private here
   50 |                 int x1, x2; boolean c;
      |                     ^~
a.cc:30:60: error: 'class Main::P' has no member named 'c'
   30 |                                         area[t][p.x1] += p.c ? 1: -1; area[t][p.x2] += p.c ? -1 : 1;
      |                                                            ^
a.cc:30:81: error: 'int Main::P::x2' is private within this context
   30 |                                         area[t][p.x1] += p.c ? 1: -1; area[t][p.x2] += p.c ? -1 : 1;
      |                                                                                 ^~
a.cc:50:25: note: declared private here
   50 |                 int x1, x2; boolean c;
      |                         ^~
a.cc:30:90: error: 'class Main::P' has no member named 'c'
   30 |                                         area[t][p.x1] += p.c ? 1: -1; area[t][p.x2] += p.c ? -1 : 1;
      |                                                                                          ^
a.cc:31:60: error: 'int Main::P::x1' is private within this context
   31 |                                         minx = min(minx, p.x1); maxx = max(maxx, p.x2);
      |                                                            ^~
a.cc:50:21: note: declared private here
   50 |                 int x1, x2; boolean c;
      |                     ^~
a.cc:31:48: error: 'min' was not declared in this scope; did you mean 'main'?
   31 |                                         minx = min(minx, p.x1); maxx = max(maxx, p.x2);
      |                                                ^~~
      |                                                main
a.cc:31:84: error: 'int Main::P::x2' is private within this context
   31 |                                         minx = min(minx, p.x1); maxx = max(maxx, p.x2);
      |                                                                                    ^~
a.cc:50:25: note: declared private here
   50 |                 int x1, x2; boolean c;
      |                         ^~
a.cc:31:72: error: 'max' was not declared in this scope; did you mean 'maxx'?
   31 |                                         minx = min(minx, p.x1); maxx = max(maxx, p.x2);
      |                                                                        ^~~
      |                                                                        maxx
a.cc:42:25: error: 'System' was not declared in this scope
   42 |                         System.out.println(a);
      |                         ^~~~~~
a.cc:43:29: error: 'r' was not declared in this scope
   43 |                         if (r == 2) System.out.println(l);
      |                             ^
a.cc: In constructor 'Main::P::P(int, int, int)':
a.cc:52:30: error: request for member 'x1' in '(Main::P*)this', which is of pointer type 'Main::P*' (maybe you meant to use '->' ?)
   52 |                         this.x1 = x1;
      |                              ^~
a.cc:53:30: error: request for member 'x2' in '(Main::P*)this', which is of pointer type 'Main::P*' (maybe you meant to use '->' ?)
   53 |                         this.x2 = x2;
      |