#include<iostream>
#include <stdio.h>
#include<algorithm>
#include <vector>
#include<cstring>
#define maxn 100005
using namespace std;
int n;
long long axs[200005], ys[200005], bxs[200005];
long long cls[200005], lazy[maxn << 4];
long long ans = 0;
struct lne {
long long x, beg, end;
int flg;
};
struct node {
long long l, r, sum;
bool avi;
};
bool cmp(lne a, lne b) {
return a.x < b.x;
}
bool cmp2( long long a, long long b) {
return a < b;
}
lne lns[200005];
node nds[maxn<<4];
void push_up( long long p) {
if (lazy[p] > 0) {
nds[p].sum = nds[p].r - nds[p].l;
}
else {
nds[p].sum = nds[p * 2].sum + nds[p * 2 + 1].sum;
}
}
void build( long long l, long long r, long long p) {
nds[p].avi = true;
if (r - l > 1) {
nds[p].l = ys[l];
nds[p].r = ys[r];
build(l, (l + r) / 2, p << 1);
build((l + r) / 2, r, (p << 1) + 1);
push_up(p);
}
else {
nds[p].l = ys[l];
nds[p].r = ys[r];
nds[p].sum = 0;
}return;
}
void update( long long nr, long long nl, long long p, int flag) {
if (nds[p].l == nl && nds[p].r == nr) {
lazy[p] += flag;
push_up(p);
return;
}
else {
if (nds[p * 2].r > nl && nds[p * 2].avi)update(min(nr, nds[p * 2].r), nl, p * 2, flag);
if (nds[p * 2 + 1].l < nr && nds[p * 2 + 1].avi)update(nr, max(nl, nds[p * 2 + 1].l), p * 2 + 1, flag);
push_up(p);
}
}
int main() {
cin >> n;
memset(lazy, 0, sizeof(lazy));
for(int i=0;i<maxn<<4;i++)nds[i].avi=false;
for (int i = 0; i < n * 2; i += 2) {
scanf("%lli %lli %lli %lli", &lns[i].x, &ys[i + 1], &lns[i + 1].x, &ys[i + 2]);
axs[i] = lns[i].x;
bxs[i] = lns[i + 1].x;
lns[i].beg = ys[i + 1];
lns[i].end = ys[i + 2];
lns[i + 1].beg = lns[i].beg;
lns[i + 1].end = lns[i].end;
lns[i].flg = 1;
lns[i + 1].flg = -1;
}
sort(lns + 0, lns + n * 2, cmp);
sort(ys + 1, ys + n * 2 + 1, cmp2);
build(1, (2 * n), 1);
update(lns[0].end, lns[0].beg, 1, lns[0].flg);
long long ans = 0;
for (int i = 1; i <= n * 2; i++) {
ans += (lns[i].x - lns[i - 1].x) * nds[1].sum;
update(lns[i].end, lns[i].beg, 1, lns[i].flg);
}
printf("%lli", ans);
//cout << ans << endl;
}
照着oiwiki上的模板打的,在本地怎么测都能过,但在洛谷上就会莫名wa(记录),感觉有点像炸精度,求大佬指点
int anss[50],q;
for (int i = 0;; i++) {
if (ans > 0) {
anss[i] = ans % 10;
ans /= 10;
}
else {
q = i;
break;
}
}
for (int i = q-1 ; i >= 0; i--) {
cout << anss[i];
}
还有把所有long long改成__int128,输出改成这样就会变成answer too short(记录)