Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define mp         make_pair
#define pb         push_back
#define fir first
#define sec second

const int N = 10010;

typedef pair<int,int> pii;

short  isexist[N]={0};
short testcase=0;
int x[N];
vector<pii> inx[N];

int req[N];

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int *xd,vector<pii> *IN){
  testcase++;
  rep(i,n){
    isexist[x1[i]]=testcase;
    isexist[x2[i]]=testcase;
  }
  rep(i,N)if (isexist[i]==testcase)x[px]=i,IN[px++].clear();

  rep(i,n){
    int j=lower_bound(xd,xd+px,x1[i])-xd;
    while(j < px && xd[j] < x2[i]){
      bool isin=false;
      rep(k,IN[j].size()){
	short Y1 = y1[i],Y2=y2[i];
	short &Y3=IN[j][k].fir;
	short &Y4=IN[j][k].sec;
	if (Y4 <= Y1 || Y2 <= Y3)continue;
	isin=true;
	Y3=min(Y1,Y3);
	Y4=max(Y2,Y4);
	break;
      }
      if (!isin)IN[j].pb((st){y1[i],y2[i]});
      j++;
    }
  }
}

pair<int,int> solve(int n,vector<st> *in,int *c){
  int area=0;
  int len=0;
  rep(i,n-1){
    if (in[i].size() == 0)continue;
    sort(in[i].begin(),in[i].end());
    short l=-1,h=-1;
    short width;
    width=c[i+1]-c[i];
    rep(j,in[i].size()){
      short &nowl=in[i][j].fir,&nowh=in[i][j].end;
      if (nowl >= h || nowh > h){
	if (nowl > h)len+=2*width;
	area+=(nowh-nowl)*width;
      }
      l=nowl;
      h=max(h,nowh);
    }
  }
  return mp(area,len);
}

main(){
  int n,q;
  static int x1[N],y1[N],x2[N],y2[N];
  while(cin>>n>>q && n){
    rep(i,n){
      cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    }
    int px=0,py=0;
    makedata(n,x1,x2,y1,y2,px,x,inx);
    pair<int,int> ansx=solve(px,inx,x);

    cout << ansx.first << endl;
    if (q == 2){
      px=0;
      makedata(n,y1,y2,x1,x2,px,x,inx);
      pair<int,int> ansy= solve(px,inx,x);      
      cout << ansx.second+ansy.second << endl;
    }
    rep(i,px)inx[i].clear();
  }
  return false;
}

Compiler output:
a.cc: In function 'void makedata(int, int*, int*, int*, int*, int&, int*, std::vector<std::pair<int, int> >*)':
a.cc:14:13: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'int'
   14 | #define fir first
a.cc:43:28: note: in expansion of macro 'fir'
   43 |         short &Y3=IN[j][k].fir;
      |                            ^~~
a.cc:15:13: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'int'
   15 | #define sec second
a.cc:44:28: note: in expansion of macro 'sec'
   44 |         short &Y4=IN[j][k].sec;
      |                            ^~~
a.cc:51:27: error: 'st' was not declared in this scope; did you mean 'std'?
   51 |       if (!isin)IN[j].pb((st){y1[i],y2[i]});
      |                           ^~
      |                           std
a.cc: At global scope:
a.cc:57:34: error: 'st' was not declared in this scope; did you mean 'std'?
   57 | pair<int,int> solve(int n,vector<st> *in,int *c){
      |                                  ^~
      |                                  std
a.cc:57:36: error: template argument 1 is invalid
   57 | pair<int,int> solve(int n,vector<st> *in,int *c){
      |                                    ^
a.cc:57:36: error: template argument 2 is invalid
a.cc: In function 'std::pair<int, int> solve(int, int*, int*)':
a.cc:61:15: error: request for member 'size' in '*(in + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   61 |     if (in[i].size() == 0)continue;
      |               ^~~~
a.cc:62:16: error: request for member 'begin' in '*(in + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   62 |     sort(in[i].begin(),in[i].end());
      |                ^~~~~
a.cc:62:30: error: request for member 'end' in '*(in + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   62 |     sort(in[i].begin(),in[i].end());
      |                              ^~~
a.cc:66:17: error: request for member 'size' in '*(in + ((sizetype)(((long unsigned int)i) * 4)))', which is of non-class type 'int'
   66 |     rep(j,in[i].size()){
      |                 ^~~~
a.cc:9:34: note: in definition of macro 'REP'
    9 | #define REP(i,b,n) for(int i=b;i<n;i++)
      |                                  ^
a.cc:66:5: note: in expansion of macro 'rep'
   66 |     rep(j,in[i].size()){
      |     ^~~
a.cc:67:24: error: invalid types 'int[int]' for array subscript
   67 |       short &nowl=in[i][j].fir,&nowh=in[i][j].end;
      |                        ^
a.cc:68:24: error: 'nowh' was not declared in this scope; did you mean 'nowl'?
   68 |       if (nowl >= h || nowh > h){
      |                        ^~~~
      |                        nowl
a.cc:73:15: error: 'nowh' was not declared in this scope; did you mean 'nowl'?
   73 |       h=max(h,nowh);
      |               ^~~~
      |               nowl
a.cc: At global scope:
a.cc:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   79 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:88:33: error: cannot convert 'std::vector<std::pair<int, int> >*' to 'int*'
   88 |     pair<int,int> ansx=solve(px,inx,x);
      |                                 ^~~
      |                                 |
      |                                 std::vector<std::pair<int, int> >*
a.cc:57:39: note:   initializing argument 2 of 'std::pair<int, int> solve(int, int*, int*)'
   57 | pair<int,int> solve(int n,vector<st> *in,int *c){
      |                           ~~~~~~~~~~~~^~
a.cc:94:36: error: cannot convert 'std::vector<std::pair<int, int> >*' to 'int*'
   94 |       pair<int,int> ansy= solve(px,inx,x);
      |                                    ^~~
      |                                    |
      |                                    std::vector<std::pair<int, int> >*
a.cc:57:39: note:   initializing argument 2 of 'std::pair<int, int> solve(int, int*, int*)'
   57 | pair<int,int> solve(int n,vector<st> *in,int *c){
      |                           ~~~~~~~~~~~~^~