Language: C++

#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for(auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

template<typename T> struct CumulativeSum2D
{
   vector<vector<T>> s;
   CumulativeSum2D(const vector<vector<T>>& v) {
      int M = v.size(), N = v[0].size();
      s.resize(M+1, vector<int>(N+1));
      for (int i = 0; i < M; i++) {
         for (int j = 0; j < N; j++) {
            s[i+1][j+1] = s[i+1][j] + v[i][j];
         }
      }
      for (int i = 0; i < M; i++) {
         for (int j = 0; j < N; j++) {
            s[i+1][j+1] += s[i][j+1];
         }
      }
   }
   int sum(int i, int j) {
      return s[i+1][j+1];
   }
   int sum(int i, int j, int k, int l) {
      return s[k+1][l+1] - s[i][l+1] - s[k+1][j] + s[i][j];
   }
};
signed main()
{
   int N; cin >> N;;
   V<P<int,int>> X(2*N), Y(2*N);
   REP(i, N) {
      cin >> X[i].first >> Y[i].first >> X[i+N].first >> Y[i+N].first;
      X[i].second = Y[i].second = i;
      X[i+N].second = Y[i+N].second = i+N;
   }
   SORT(X); SORT(Y);
   V<int> idx(2*N), idy(2*N);
   REP(i, 2*N) {
      idx[X[i].second] = i;
      idy[Y[i].second] = i;
   }
   V<V<int>> s(2*N, V<int>(2*N));
   REP(i, N) {
      s[idy[i]][idx[i]]++;
      s[idy[i]][idx[i+N]]--;
      s[idy[i+N]][idx[i]]--;
      s[idy[i+N]][idx[i+N]]++;
   }
   CumulativeSum2D<int> S(s);
   int ans = 0;
   REP(i, 2*N-1) REP(j, 2*N-1) if (S.sum(i,j) > 0) {
      ans += (Y[i+1].first - Y[i].first) * (X[j+1].first - X[j].first);
   }
   cout << ans << endl;

   return 0;
}



Compiler output:
a.cc:27:41: error: 'pair' does not name a type
   27 | template<typename T,typename U> using P=pair<T,U>;
      |                                         ^~~~
a.cc:28:30: error: 'vector' does not name a type
   28 | template<typename T> using V=vector<T>;
      |                              ^~~~~~
a.cc:31:27: error: 'vector' was not declared in this scope
   31 | template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
      |                           ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define int long long int
a.cc:31:35: error: expected primary-expression before '>' token
   31 | template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
      |                                   ^
a.cc:31:37: error: 'v' was not declared in this scope
   31 | template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
      |                                     ^
a.cc:31:39: error: expected ';' before '{' token
   31 | template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
      |                                       ^
      |                                       ;
a.cc:32:23: error: redefinition of 'template<class T> T sum'
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                       ^~~
a.cc:31:23: note: 'template<class T> T sum<T>' previously declared here
   31 | template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
      |                       ^~~
a.cc:32:27: error: 'vector' was not declared in this scope
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                           ^~~~~~
a.cc:32:27: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:32:35: error: expected primary-expression before '>' token
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                                   ^
a.cc:32:37: error: 'v' was not declared in this scope
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                                     ^
a.cc:1:13: error: expected primary-expression before 'long'
    1 | #define int long long int
      |             ^~~~
a.cc:32:39: note: in expansion of macro 'int'
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                                       ^~~
a.cc:1:13: error: expected primary-expression before 'long'
    1 | #define int long long int
      |             ^~~~
a.cc:32:45: note: in expansion of macro 'int'
   32 | template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
      |                                             ^~~
a.cc:33:27: error: 'vector' was not declared in this scope
   33 | template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
      |                           ^~~~~~
a.cc:33:27: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:33:35: error: expected primary-expression before '>' token
   33 | template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
      |                                   ^
a.cc:33:37: error: 'v' was not declared in this scope
   33 | template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
      |                                     ^
a.cc:33:39: error: expected ';' before '{' token
   33 | template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
      |                                       ^
      |                                       ;
a.cc:34:27: error: 'vector' was not declared in this scope
   34 | template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
      |                           ^~~~~~
a.cc:34:27: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:34:35: error: expected primary-expression before '>' token
   34 | template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
      |                                   ^
a.cc:34:37: error: 'v' was not declared in this scope
   34 | template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
      |                                     ^
a.cc:34:39: error: expected ';' before '{' token
   34 | template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
      |                                       ^
      |                                       ;
a.cc:35:33: error: 'vector' was not declared in this scope
   35 | template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
      |                                 ^~~~~~
a.cc:35:33: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:35:41: error: expected primary-expression before '>' token
   35 | template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
      |                                         ^
a.cc:35:43: error: 'v' was not declared in this scope
   35 | template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
      |                                           ^
a.cc:35:45: error: expected ';' before '{' token
   35 | template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
      |                                             ^
      |                                             ;
a.cc:36:33: error: 'vector' was not declared in this scope
   36 | template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}
      |                                 ^~~~~~
a.cc:36:33: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:36:41: error: expected primary-expression before '>' token
   36 | template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}
      |                                         ^
a.cc:36:43: error: 'v' was not declared in this scope
   36 | template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}
      |                                           ^
a.cc:36:45: error: expected ';' before '{' token
   36 | template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}
      |                                             ^
      |                                             ;
a.cc:40:26: error: declaration of 'operator<<' as non-function
   40 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
      |                          ^~~~~~~~
a.cc:40:37: error: 'ostream' was not declared in this scope
   40 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
      |                                     ^~~~~~~
a.cc:1:1: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #define int long long int
a.cc:40:45: error: 's' was not declared in this scope
   40 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
      |                                             ^
a.cc:40:47: error: expected primary-expression before 'const'
   40 | template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
      |                                               ^~~~~
a.cc:41:37: error: declaration of 'operator<<' as non-function
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                     ^~~~~~~~
a.cc:41:48: error: 'ostream' was not declared in this scope
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                                ^~~~~~~
a.cc:41:48: note: 'std::ostream' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc:41:56: error: 's' was not declared in this scope
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                                        ^
a.cc:41:58: error: expected primary-expression before 'const'
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                                          ^~~~~
a.cc:41:72: error: expected primary-expression before '>' token
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                                                        ^
a.cc:41:74: error: 'p' was not declared in this scope
   41 | template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
      |                                                                          ^
a.cc:42:26: error: declaration of 'operator<<' as non-function
   42 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
      |                          ^~~~~~~~
a.cc:42:37: error: 'ostream' was not declared in this scope
   42 | template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
      |                                     ^~~~~~~
a.cc:42:37: note: