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

const int N = 10010;

class st{
public:
  short beg,end;
  bool operator<(const st &)const;
};

bool st::operator<(const st & a)const{
  if (beg != a.beg)return beg < a.beg;
  return end < a.end;
}

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

int req[N];

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int *xd,vector<st> *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();
  //cout <<"allx ";rep(i,px)cout << x[i]<<" ";cout << endl;

  rep(i,px)req[i]=0;
  rep(i,n){
    int j=lower_bound(xd,xd+px,x1[i])-xd;
    while(j < px && xd[j] < x2[i]){
      bool isin=false;
      bool iscontinue=false;
      rep(k,req[j]){
	if (y1[i] <= IN[j][k].begin && IN[j][k].end <= y2[i]){
	  isin=true;
	  in[j][k].begin=y1[i];
	  in[j][k].end=y2[i];
	  break;
	}
      }
      if (isin)req[j]++;
      j++;
    }
  }

  rep(i,px)IN[i]=vector<st>(req[i]),req[i]=0;

  rep(i,n){
    int j=lower_bound(xd,xd+px,x1[i])-xd;
    while(j < px && xd[j] < x2[i]){
      bool isin=false;
      bool iscontinue=false;
      rep(k,req[j]){
	if (y1[i] <= IN[j][k].begin && IN[j][k].end <= y2[i]){
	  isin=true;
	  in[j][k].begin=y1[i];
	  in[j][k].end=y2[i];
	  break;
	}
      }
      if (!isin)IN[j][req[j]++]=(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].beg,&nowh=in[i][j].end;
      //cout << nowl <<" "<< nowh <<" " << l<<" " << h << endl;
      if (nowl > h){
	len+=2*width;
	//cout << c[i]<<" " << c[i]<<" " << nowh<<" " << nowl << endl;
	area+=(nowh-nowl)*width;
      }else if (nowl == h){
	//cout << c[i]<<" " << c[i]<<" " << nowh<<" " << nowl << endl;
	area+=(nowh-nowl)*width;
      }else if (nowh > h){
	//cout << c[i]<<" " << c[i]<<" " << nowh<<" " << h << endl;
	area+=(nowh-h)*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<st>*)':
a.cc:52:31: error: '__gnu_cxx::__alloc_traits<std::allocator<st>, st>::value_type' {aka 'class st'} has no member named 'begin'; did you mean 'beg'?
   52 |         if (y1[i] <= IN[j][k].begin && IN[j][k].end <= y2[i]){
      |                               ^~~~~
      |                               beg
a.cc:54:11: error: 'in' was not declared in this scope; did you mean 'i'?
   54 |           in[j][k].begin=y1[i];
      |           ^~
      |           i
a.cc:72:31: error: '__gnu_cxx::__alloc_traits<std::allocator<st>, st>::value_type' {aka 'class st'} has no member named 'begin'; did you mean 'beg'?
   72 |         if (y1[i] <= IN[j][k].begin && IN[j][k].end <= y2[i]){
      |                               ^~~~~
      |                               beg
a.cc:74:11: error: 'in' was not declared in this scope; did you mean 'i'?
   74 |           in[j][k].begin=y1[i];
      |           ^~
      |           i
a.cc:79:42: warning: narrowing conversion of '*(y1 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   79 |       if (!isin)IN[j][req[j]++]=(st){y1[i],y2[i]};
      |                                      ~~~~^
a.cc:79:48: warning: narrowing conversion of '*(y2 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   79 |       if (!isin)IN[j][req[j]++]=(st){y1[i],y2[i]};
      |                                            ~~~~^
a.cc: At global scope:
a.cc:116:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  116 | main(){
      | ^~~~