来炫耀一下我的1A
#include<bits/stdc++.h>
#define x1 _x1
#define y1 _y1
#define x2 _x2
#define y2 _y2
#define lson (node<<1)
#define rson (node<<1|1)
using namespace std;
const int N=100001;
struct data{
int x1,x2,y,v;
}a[N<<1];
int n;
map<int,int> mp;
struct seg{
int cnt,lins,lbd,rbd,m;
}t[N<<3];
int xx[N<<1];
void read(int &x){
char ch=getchar();x=0;int w=1;
for(;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
x*=w;
}
int cmp(const data &q,const data &w){
if (q.y==w.y) return q.v>w.v;
return q.y<w.y;
}
void update(int node,int L,int r){
seg &q=t[node];
if (q.cnt) return;
q.lins=t[lson].lins+t[rson].lins;
if (t[lson].rbd&&t[rson].lbd) q.lins--;
q.lbd=t[lson].lbd;q.rbd=t[rson].rbd;
q.m=t[lson].m+t[rson].m;
}
void cover(int node,int L,int r,int s){
seg &q=t[node];
q.cnt+=s;
if (q.cnt){
q.lins=q.lbd=q.rbd=1;
q.m=xx[r]-xx[L-1];
} else{
if (L==r){
q.lins=q.lbd=q.rbd=q.m=0;
return;
}
update(node,L,r);
}
}
void insert(int node,int L,int r,int x,int y,int v){
seg &q=t[node];
if (L>=x&&r<=y){
cover(node,L,r,v);
return;
}
int mid=L+r>>1;
if (x<=mid) insert(lson,L,mid,x,y,v);
if (y>mid) insert(rson,mid+1,r,x,y,v);
update(node,L,r);
}
int main(){
read(n);
int x1,y1,x2,y2;
for(int i=1;i<=n;i++){
read(x1);read(y1);
read(x2);read(y2);
mp[x1]=1;mp[x2]=1;
a[i*2-1]=(data){x1,x2,y1,1};
a[i*2]=(data){x1,x2,y2,-1};
}
int cnt=-1;
for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
it->second=++cnt,xx[cnt]=it->first;
sort(a+1,a+1+(n<<1),cmp);
int pre=0,ans=0;
for(int i=1;i<=n<<1;i++){
x1=mp[a[i].x1];x2=mp[a[i].x2];
ans+=2*t[1].lins*(a[i].y-a[i-1].y);
insert(1,1,cnt,x1+1,x2,a[i].v);
ans+=abs(t[1].m-pre);
pre=t[1].m;
}
cout<<ans<<endl;
return 0;
}