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];
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]){
      //IN[j].pb((st){y1[i],y2[i]});
      req[j]++;
      j++;
    }
  }

  rep(i,px)IN[i]=malloc(sizeof(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]){
      //IN[j].pb((st){y1[i],y2[i]});
      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 (req[i] == 0)continue;
    sort(in[i],in[i]+req[i]);
    short l=-1,h=-1;
    short width;
    width=c[i+1]-c[i];
    rep(j,req[i]){
      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:55:42: error: no match for 'operator=' (operand types are 'std::vector<st>' and 'void*')
   55 |   rep(i,px)IN[i]=malloc(sizeof(st)*req[i]),req[i]=0;
      |                                          ^
In file included from /usr/include/c++/14/vector:72,
                 from a.cc:4:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = st; _Alloc = std::allocator<st>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'void*' to 'const std::vector<st>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = st; _Alloc = std::allocator<st>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'void*' to 'std::vector<st>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = st; _Alloc = std::allocator<st>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'void*' to 'std::initializer_list<st>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:61:32: warning: narrowing conversion of '*(y1 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   61 |       IN[j][req[j]++]=(st){y1[i],y2[i]};
      |                            ~~~~^
a.cc:61:38: warning: narrowing conversion of '*(y2 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   61 |       IN[j][req[j]++]=(st){y1[i],y2[i]};
      |                                  ~~~~^
a.cc: In function 'std::pair<int, int> solve(int, std::vector<st>*, int*)':
a.cc:72:21: error: no match for 'operator+' (operand types are 'std::vector<st>' and 'int')
   72 |     sort(in[i],in[i]+req[i]);
      |                ~~~~~^~~~~~~
      |                    |      |
      |                    |      int
      |                    std::vector<st>
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   mismatched types 'const _CharT*' and 'std::vector<st>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:72:27: note:   'std::vector<st>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   72 |     sort(in[i],in[i]+req[i]);
      |                           ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:72:27: