自闭了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<stack>
#include<list>
#include<fstream>
#define SYNC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define F(i,m,n) for(int i=m;i<=n;i++)
#define f(i,m,n) for(int i=m;i>=n;i--)
#define debug(n) if(deb==1) cout<<#n<<"="<<n<<endl
#define deb(n) if(deb==1) cout<<#n<<"="<<n<<" "
#define div(ch) if(deb==1) { for(int i=1;i<=40;i++) cout<<#ch; cout<<endl; }
#define mm(A,n) memset(A,n,sizeof(A))
#define lowbit(x) (x&(-x))
#define PII pair<int,int>
typedef long long LL;
const int maxn = 1e5 + 10;
const int maxm = 3e7 + 10;
const int mod = 571373;
const double eps = 1e-9;
const bool deb = 0;
using namespace std;
struct type {
int l, r, v, cnt;
}tree[maxn * 8];
struct type2 {
int l, r, h, v;
type2() {}
type2(int x1, int x2, int hi, int val) {
l = x1, r = x2, h = hi, v = val;
}
bool operator <(const type2& a)const {
return h < a.h;
}
}line[maxn * 2];
int x[maxn * 2];
void spepushup(int rt) {
tree[rt].l = tree[rt * 2].l;
tree[rt].r = tree[rt * 2 + 1].r;
if (tree[rt].cnt) tree[rt].v = x[tree[rt].r + 1] - x[tree[rt].l];
else tree[rt].v = tree[rt * 2].v + tree[rt * 2 + 1].v;
}
void pushup(int rt) {
if (tree[rt].cnt) tree[rt].v = x[tree[rt].r + 1] - x[tree[rt].l];
else tree[rt].v = tree[rt * 2].v + tree[rt * 2 + 1].v;
}
void build(int l, int r, int rt) {
if (l == r) {
tree[rt].l = tree[rt].r = l;
tree[rt].cnt = 0;
tree[rt].v = 0;
return;
}
int mid = (l + r) / 2;
build(l, mid, rt * 2);
build(mid + 1, r, rt * 2 + 1);
spepushup(rt);
}
void update(int l, int r, int rt, int v) {
if (tree[rt].l >= l && tree[rt].r <= r) {
tree[rt].cnt += v;
pushup(rt);
return;
}
if (tree[rt * 2].r >= l) update(l, r, rt * 2, v);
if (tree[rt * 2 + 1].l <= r) update(l, r, rt * 2 + 1, v);
pushup(rt);
}
void oper() {
int n;
cin >> n;
int x1, y1, x2, y2;
int a = 0, b = 0;
F(i, 1, n) {
cin >> x1 >> y1 >> x2 >> y2;
x[++a] = x1; line[++b] = type2(x1, x2, y1, -1);
deb(b); deb(line[b].l); debug(line[b].r);
x[++a] = x2; line[++b] = type2(x1, x2, y2, 1);
}
sort(x + 1, x + a + 1);
sort(line + 1, line + b + 1);
int k = unique(x + 1, x + a + 1) - x - 1;
LL ans = 0;
build(1, a, 1);
F(i, 1, b) {
div(__);
debug(i);
deb(line[i].l); deb(line[i].r);; deb(line[i].v); debug(line[i].h);
int l = lower_bound(x + 1, x + k + 1, line[i].l) - x;
int r = lower_bound(x + 1, x + k + 1, line[i].r) - x;
r--;
deb(l); debug(r);
update(l, r, 1, -line[i].v);
if (i < b) ans += tree[1].v * (line[i+ 1].h - line[i].h);
/*deb(l); debug(r);
F(i, 1, n * 4) {
deb(i); deb(tree[i].l); deb(tree[i].r); debug(tree[i].v);
}
debug(ans);*/
}
cout << ans;
}
int main() {
SYNC;
int t = 1;
//cin >> t;
while (t--)
oper();
return 0;
}
/*Avoid Stereotypes, Think More, and Code Less.*/
/*Instead of focusing on troublesome old ideas, it's
better to learn or think about efficient new methods*/