Language: C++

include <cstdio>
#include <utility>
#include <map>

using namespace std;

int n;
short min_x1, max_x2, min_y1, max_y2;
short x1, x2, y1, y2;
map<pair<short, short>, short> *variation;
char tiles[10002][10002];

void variation_inc(short x, short y) {
    short value;
    map<pair<short, short>, short>::iterator location;

    location = variation->find(make_pair(x, y));
    if (location != variation->end()) {
        value = location->second + 1;
    } else {
        value = 1;
    }

    variation->erase(make_pair(x, y));
	
    if (value != 0) {
    	variation->insert(pair<pair<short, short>, short>(make_pair(x,y), value));
    }

    return ;
}

void variation_dec(short x, short y) {
    short value;
    map<pair<short, short>, short>::iterator location;

    location = variation->find(make_pair(x, y));
    if (location != variation->end()) {
        value = location->second - 1;
    } else {
        value = -1;
    }

    variation->erase(make_pair(x, y));

    if (value != 0) {
    	variation->insert(pair<pair<short, short>, short>(make_pair(x,y), value));
    }

    return ;
}

short variation_return(short x, short y) {
    short value;
    map<pair<short, short>, short>::iterator location;

    location = variation->find(make_pair(x, y));
    if (location != variation->end()) {
    	value = location->second;
    } else {
        value = 0;
    }

    return value;
}

void pre_process() {
    short i;
    short calc[2][10002];
	
	for (i=0;i<2;i++) {
        int j;
        for (j=0;j<10002;j++) {
            calc[i][j] = 0;
        }
	}

    for (i=min_y1-1;i<max_y2+1;i++) {
        int j;
        
        for (j=min_x1-1;j<max_x2+1;j++) {
            calc[1][j] = variation_return(j, i);

            calc[1][j] += calc[1][j-1];
            calc[1][j] += calc[0][j];
        	calc[1][j] -= calc[0][j-1];
        }

        for (j=min_x1;j<max_x2+1;j++) {
            tiles[i][j] = ((calc[0][j] > 0) ? 1 : 0);
            calc[0][j] = calc[1][j];
        }
    }

    return;
}

int surface() {
    short i;
    int sum = 0;

    for (i=min_y1;i<max_y2+1;i++) {
        int j;
        for (j=min_x1;j<max_x2+1;j++) {
            if (tiles[i][j]) {
                sum++;
            }
        }
    }

    return sum;
}

int perimeter() {
    short i;
    int sum = 0;

    for (i=min_y1;i<max_y2+2;i++) {
        short j;
        for (j=min_x1;j<max_x2+2;j++) {
            if (tiles[i][j] + tiles[i-1][j] == 1) {
                sum++;
            }

            if (tiles[i][j] + tiles[i][j-1] == 1) {
                sum++;
            }
        }
    }

    return sum;
}

int main() {
    while (1) {
        short i;
        int r;

        scanf("%d %d", &n, &r);
        if (n == 0 && r ==0) return 0;

    	variation = new map<pair<short, short>, short>();

        min_x1 = 10000;
        min_y1 = 10000;
        max_x2 = 0;
        max_y2 = 0;
        for (i=0;i<n;i++) {
            scanf("%hd %hd %hd %hd", &x1, &y1, &x2, &y2);
            x1++;
            x2++;
            y1++;
            y2++;
            if (min_x1 > x1) min_x1 = x1;
            if (max_x2 < x2) max_x2 = x2;
            if (min_y1 > y1) min_y1 = y1;
            if (max_y2 < y2) max_y2 = y2;
        	variation_inc(x1, y1);
        	variation_dec(x1, y2);
        	variation_dec(x2, y1);
        	variation_inc(x2, y2);
        }

        for (i=0;i<10002;i++) {
            short j;
            for (j=0;j<10002;j++) {
                tiles[i][j] = 0;
            }
        }
    	
        pre_process();

        printf("%d\n", surface());

        if (r == 2) {
            printf("%d\n", perimeter());
        }        
    	
    	delete variation;
    }
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <cstdio>
      | ^~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/utility:69,
                 from a.cc:2:
/usr/include/c++/14/type_traits:295:27: error: 'size_t' has not been declared
  295 |   template <typename _Tp, size_t = sizeof(_Tp)>
      |                           ^~~~~~
/usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                 ^~~~~~~~~
/usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid
  666 |     struct is_null_pointer<std::nullptr_t>
      |                                          ^
/usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid
  670 |     struct is_null_pointer<const std::nullptr_t>
      |                                                ^
/usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid
  674 |     struct is_null_pointer<volatile std::nullptr_t>
      |                                                   ^
/usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid
  678 |     struct is_null_pointer<const volatile std::nullptr_t>
      |                                                         ^
/usr/include/c++/14/type_traits:984:26: error: 'size_t' has not been declared
  984 |   template<typename _Tp, size_t _Size>
      |                          ^~~~~~
/usr/include/c++/14/type_traits:985:40: error: '_Size' was not declared in this scope
  985 |     struct __is_array_known_bounds<_Tp[_Size]>
      |                                        ^~~~~
/usr/include/c++/14/type_traits:985:46: error: template argument 1 is invalid
  985 |     struct __is_array_known_bounds<_Tp[_Size]>
      |                                              ^
/usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid
 1429 |     : public integral_constant<std::size_t, alignof(_Tp)>
      |                                                         ^
/usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid
 1438 |     : public integral_constant<std::size_t, 0> { };
      |                                              ^
/usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared
 1440 |   template<typename _Tp, std::size_t _Size>
      |                          ^~~
/usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope
 1441 |     struct rank<_Tp[_Size]>
      |                     ^~~~~
/usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid
 1441 |     struct rank<_Tp[_Size]>
      |                           ^
/usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid
 1442 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                     ^~~~~~
/usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid
 1446 |     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
      |                                                                 ^
/usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1451:32: error: 'size_t' was not declared in this scope
 1451 |     : public integral_constant<size_t, 0> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:64:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
   63 | #include <bits/version.h>
  +++ |+#include <cstddef>
   64 | 
/usr/include/c++/14/type_traits:1451:41: error: template argument 1 is invalid
 1451 |     : public integral_constant<size_t, 0> { };
      |                                         ^
/usr/include/c++/14/type_traits:1451:41: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1453:26: error: 'size_t' has not been declared
 1453 |   template<typename _Tp, size_t _Size>
      |                          ^~~~~~
/usr/include/c++/14/type_traits:1454:23: error: '_Size' was not declared in this scope
 1454 |     struct extent<_Tp[_Size], 0>
      |                       ^~~~~
/usr/include/c++/14/type_traits:1454:32: error: template argument 1 is invalid
 1454 |     struct extent<_Tp[_Size], 0>
      |                                ^
/usr/include/c++/14/type_traits:1455:32: error: 'size_t' was not declared in this scope
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:1455:32: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1455:40: error: '_Size' was not declared in this scope
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                        ^~~~~
/usr/include/c++/14/type_traits:1455:45: error: template argument 1 is invalid
 1455 |     : public integral_constant<size_t, _Size> { };
      |                                             ^
/usr/include/c++/14/type_traits:1455:45: error: template argument 2 is invalid
/usr/include/c++/14/type_traits:1457:42: error: 'size_t' has not been declared
 1457 |   template<typename _Tp, unsigned _Uint, size_t _Size>
      |                                          ^~~~~~
/usr/include/c++/14/type_traits:1458:23: error: '_Size' was not declared in this scope
 1458 |     struct extent<_Tp[_Size], _Uint>
      |                       ^~~~~
/usr/include/c++/14/type_traits:1458:36: error: template argument 1 is invalid
 1458 |     struct extent<_Tp[_Size], _Uint>
      |                                    ^
/usr/include/c++/14/type_traits:1463:32: error: 'size_t' was not declared in this scope
 1463 |     : public integral_constant<size_t, 0> { };
      |                                ^~~~~~
/usr/include/c++/14/type_traits:1463:32: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1463:41: error: template argument 1 is invalid
 1463 |     : public integral_constant<size_t, 0> { };
      |                                         ^
/usr/include/c++/14/type_traits:1463:41: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1857:26: error: 'size_t' does not name a type
 1857 |       { static constexpr size_t __size = sizeof(_Tp); };
      |                          ^~~~~~
/usr/include/c++/14/type_traits:1857:26: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/c++/14/type_traits:1859:14: error: 'size_t' has not been declared
 1859 |     template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1859:48: error: '_Sz' was not declared in this scope
 1859 |     template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
      |                                                ^~~
/usr/include/c++/14/type_traits:1860:14: error: no default argument for '_Tp'
 1860 |       struct __select;
      |              ^~~~~~~~
/usr/include/c++/14/type_traits:1862:14: error: 'size_t' has not been declared
 1862 |     template<size_t _Sz, typename _Uint, typename... _UInts>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1863:23: error: '_Sz' was not declared in this scope
 1863 |       struct __select<_Sz, _List<_Uint, _UInts...>, true>
      |                       ^~~
/usr/include/c++/14/type_traits:1863:57: error: template argument 1 is invalid
 1863 |       struct __select<_Sz, _List<_Uint, _UInts...>, true>
      |                                                         ^
/usr/include/c++/14/type_traits:1866:14: error: 'size_t' has not been declared
 1866 |     template<size_t _Sz, typename _Uint, typename... _UInts>
      |              ^~~~~~
/usr/include/c++/14/type_traits:1867:23: error: '_Sz' was not declared in this scope
 1867 |       struct __select<_Sz, _List<_Uint, _UInts...>, false>
      |                       ^~~
/usr/include/c++/14/type_traits:1867:58: error: template argument 1 is invalid
 1867 |       struct __select<_Sz, _List<_Uint, _UInts...>, false>
      |                                                          ^
/usr/include/c++/14/type_traits:1868:18: error: '_Sz' was not declared in this scope
 1868 |       : __select<_Sz, _List<_UInts...>>
      |                  ^~~
/usr/include/c++/14/type_traits:1868:38: error: template argument 1 is invalid
 1868 |       : __select<_Sz, _List<_UInts...>>
      |                                      ^~
/usr/include/c++/14/type_traits:1859:60: error: '__size' is not a member of 'std::__make_unsigned_selector_base::_List<unsigned char, short unsigned int, unsigned int, long unsigned int, long long unsigned int>'
 1859 |     template<size_t _Sz, typename _Tp, bool = (_Sz <= _Tp::__size)>
      |                                                            ^~~~~