From 69f6f57535936ecf031af1b6e5a45d7635561050 Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Sun, 13 Feb 2022 08:08:42 +0800 Subject: [PATCH] =?UTF-8?q?[80pts]=20#1256.=20=E7=89=A7=E5=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/49209 --- S2OJ/1256/1256.cpp | 154 ++++++++++++++++++++++++++++++++++++++ S2OJ/1256/data/data1.in | 3 + S2OJ/1256/data/data1.out | 3 + S2OJ/1256/data/data10.in | 3 + S2OJ/1256/data/data10.out | 3 + S2OJ/1256/data/data2.in | 3 + S2OJ/1256/data/data2.out | 3 + S2OJ/1256/data/data3.in | 3 + S2OJ/1256/data/data3.out | 3 + S2OJ/1256/data/data4.in | 3 + S2OJ/1256/data/data4.out | 3 + S2OJ/1256/data/data5.in | 3 + S2OJ/1256/data/data5.out | 3 + S2OJ/1256/data/data6.in | 3 + S2OJ/1256/data/data6.out | 3 + S2OJ/1256/data/data7.in | 3 + S2OJ/1256/data/data7.out | 3 + S2OJ/1256/data/data8.in | 3 + S2OJ/1256/data/data8.out | 3 + S2OJ/1256/data/data9.in | 3 + S2OJ/1256/data/data9.out | 3 + 21 files changed, 214 insertions(+) create mode 100644 S2OJ/1256/1256.cpp create mode 100644 S2OJ/1256/data/data1.in create mode 100644 S2OJ/1256/data/data1.out create mode 100644 S2OJ/1256/data/data10.in create mode 100644 S2OJ/1256/data/data10.out create mode 100644 S2OJ/1256/data/data2.in create mode 100644 S2OJ/1256/data/data2.out create mode 100644 S2OJ/1256/data/data3.in create mode 100644 S2OJ/1256/data/data3.out create mode 100644 S2OJ/1256/data/data4.in create mode 100644 S2OJ/1256/data/data4.out create mode 100644 S2OJ/1256/data/data5.in create mode 100644 S2OJ/1256/data/data5.out create mode 100644 S2OJ/1256/data/data6.in create mode 100644 S2OJ/1256/data/data6.out create mode 100644 S2OJ/1256/data/data7.in create mode 100644 S2OJ/1256/data/data7.out create mode 100644 S2OJ/1256/data/data8.in create mode 100644 S2OJ/1256/data/data8.out create mode 100644 S2OJ/1256/data/data9.in create mode 100644 S2OJ/1256/data/data9.out diff --git a/S2OJ/1256/1256.cpp b/S2OJ/1256/1256.cpp new file mode 100644 index 00000000..9dded47c --- /dev/null +++ b/S2OJ/1256/1256.cpp @@ -0,0 +1,154 @@ +#pragma GCC optimize(3) +#pragma GCC target("avx") +#pragma GCC optimize("Ofast") +#pragma GCC optimize("inline") +#pragma GCC optimize("-fgcse") +#pragma GCC optimize("-fgcse-lm") +#pragma GCC optimize("-fipa-sra") +#pragma GCC optimize("-ftree-pre") +#pragma GCC optimize("-ftree-vrp") +#pragma GCC optimize("-fpeephole2") +#pragma GCC optimize("-ffast-math") +#pragma GCC optimize("-fsched-spec") +#pragma GCC optimize("unroll-loops") +#pragma GCC optimize("-falign-jumps") +#pragma GCC optimize("-falign-loops") +#pragma GCC optimize("-falign-labels") +#pragma GCC optimize("-fdevirtualize") +#pragma GCC optimize("-fcaller-saves") +#pragma GCC optimize("-fcrossjumping") +#pragma GCC optimize("-fthread-jumps") +#pragma GCC optimize("-funroll-loops") +#pragma GCC optimize("-fwhole-program") +#pragma GCC optimize("-freorder-blocks") +#pragma GCC optimize("-fschedule-insns") +#pragma GCC optimize("inline-functions") +#pragma GCC optimize("-ftree-tail-merge") +#pragma GCC optimize("-fschedule-insns2") +#pragma GCC optimize("-fstrict-aliasing") +#pragma GCC optimize("-fstrict-overflow") +#pragma GCC optimize("-falign-functions") +#pragma GCC optimize("-fcse-skip-blocks") +#pragma GCC optimize("-fcse-follow-jumps") +#pragma GCC optimize("-fsched-interblock") +#pragma GCC optimize("-fpartial-inlining") +#pragma GCC optimize("no-stack-protector") +#pragma GCC optimize("-freorder-functions") +#pragma GCC optimize("-findirect-inlining") +#pragma GCC optimize("-fhoist-adjacent-loads") +#pragma GCC optimize("-frerun-cse-after-loop") +#pragma GCC optimize("inline-small-functions") +#pragma GCC optimize("-finline-small-functions") +#pragma GCC optimize("-ftree-switch-conversion") +#pragma GCC optimize("-foptimize-sibling-calls") +#pragma GCC optimize("-fexpensive-optimizations") +#pragma GCC optimize("-funsafe-loop-optimizations") +#pragma GCC optimize("inline-functions-called-once") +#pragma GCC optimize("-fdelete-null-pointer-checks") + +#include +#include +#include +#include + +const int N = 2e5 + 5; + +int n; +long long ans; +std::vector ys; + +struct segment { + int x, y1, y2, k; + + segment() + : x(0), y1(0), y2(0), k(0) {} + segment(int _x, int _y1, int _y2, int _k) + : x(_x), y1(_y1), y2(_y2), k(_k) {} + + bool operator<(const segment& b) const { + return x == b.x ? k > b.k : x < b.x; + } +} seg[N << 1]; + +struct rectangle { + int x1, y1, x2, y2; +} q[N]; + +struct node { + int l, r; + long long cnt, len; + + node() + : l(0), r(0), cnt(0), len(0) {} + node(int _l, int _r) + : l(_l), r(_r), cnt(0), len(0) {} +} tr[N << 3]; + +inline int find(int y) { + return std::lower_bound(ys.begin(), ys.end(), y) - ys.begin(); +} + +inline void pushup(int u) { + if (tr[u].cnt) { + tr[u].len = ys[tr[u].r + 1] - ys[tr[u].l]; + } else if (tr[u].l != tr[u].r) { + tr[u].len = tr[u << 1].len + tr[u << 1 | 1].len; + } else { + tr[u].len = 0; + } +} + +void build(int u, int l, int r) { + tr[u] = node(l, r); + if (l == r) return; + int mid = l + r >> 1; + build(u << 1, l, mid); + build(u << 1 | 1, mid + 1, r); +} + +void modify(int u, int l, int r, int x) { + if (l <= tr[u].l && tr[u].r <= r) { + tr[u].cnt += x; + } else { + int mid = tr[u].l + tr[u].r >> 1; + if (l <= mid) modify(u << 1, l, r, x); + if (r > mid) modify(u << 1 | 1, l, r, x); + } + pushup(u); +} + +void solve() { + std::sort(ys.begin(), ys.end()); + std::sort(seg, seg + n * 2); + ys.erase(std::unique(ys.begin(), ys.end()), ys.end()); + build(1, 0, ys.size() - 2); + for (int i = 0; i < n * 2; i++) { + int last = tr[1].len; + modify(1, find(seg[i].y1), find(seg[i].y2) - 1, seg[i].k); + ans += abs(tr[1].len - last); + } + ys.clear(); +} + +int main() { + scanf("%d", &n); + for (int i = 0; i < n; i++) { + scanf("%d%d%d%d", &q[i].x1, &q[i].y1, &q[i].x2, &q[i].y2); + } + for (int i = 0, j = 0; i < n; i++) { + seg[j++] = segment(q[i].x1, q[i].y1, q[i].y2, 1); + seg[j++] = segment(q[i].x2, q[i].y1, q[i].y2, -1); + ys.push_back(q[i].y1); + ys.push_back(q[i].y2); + } + solve(); + for (int i = 0, j = 0; i < n; i++) { + seg[j++] = segment(q[i].y1, q[i].x1, q[i].x2, 1); + seg[j++] = segment(q[i].y2, q[i].x1, q[i].x2, -1); + ys.push_back(q[i].x1); + ys.push_back(q[i].x2); + } + solve(); + printf("%lld\n", ans); + return 0; +} diff --git a/S2OJ/1256/data/data1.in b/S2OJ/1256/data/data1.in new file mode 100644 index 00000000..505a1619 --- /dev/null +++ b/S2OJ/1256/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:605e20e26b88d5304fd55498f2cd94bd409d23a349fa2dc9c17b7e252a1ce73a +size 30 diff --git a/S2OJ/1256/data/data1.out b/S2OJ/1256/data/data1.out new file mode 100644 index 00000000..654a9104 --- /dev/null +++ b/S2OJ/1256/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa108d8b7635c8eb6a8729dc98c3af9a6f410c72efe9ebf88f02fa9dcce1898d +size 7 diff --git a/S2OJ/1256/data/data10.in b/S2OJ/1256/data/data10.in new file mode 100644 index 00000000..a5e2b454 --- /dev/null +++ b/S2OJ/1256/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:93d013f8fac98b644c726572572fcc1238b3a0b30c2773a9d9883014e623bd0a +size 831992 diff --git a/S2OJ/1256/data/data10.out b/S2OJ/1256/data/data10.out new file mode 100644 index 00000000..c0305aa8 --- /dev/null +++ b/S2OJ/1256/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3e6dbba9def26c6c11257508d6f4bf196fa1025007ebf1fce1ff4257a1a1dd6 +size 6 diff --git a/S2OJ/1256/data/data2.in b/S2OJ/1256/data/data2.in new file mode 100644 index 00000000..0967504f --- /dev/null +++ b/S2OJ/1256/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:735b72c4bb8419b89c9040568fa8b12d9c640cf378a918930184173e9189a450 +size 1329396 diff --git a/S2OJ/1256/data/data2.out b/S2OJ/1256/data/data2.out new file mode 100644 index 00000000..357caf30 --- /dev/null +++ b/S2OJ/1256/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6afbba368913bb522dcdaaa459b6fb662bc24abacb1949e8f06effbdcb769326 +size 8 diff --git a/S2OJ/1256/data/data3.in b/S2OJ/1256/data/data3.in new file mode 100644 index 00000000..7798639f --- /dev/null +++ b/S2OJ/1256/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:552f26b7bb22f11472966f19b70156b6f84b7c94efacda991849964cfb7f0e5f +size 5317884 diff --git a/S2OJ/1256/data/data3.out b/S2OJ/1256/data/data3.out new file mode 100644 index 00000000..b12bc05f --- /dev/null +++ b/S2OJ/1256/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63afa5bc20592e4977e903570096378b7e51129cc49ff6ebb3c59f0fadf5e03a +size 8 diff --git a/S2OJ/1256/data/data4.in b/S2OJ/1256/data/data4.in new file mode 100644 index 00000000..289f70f9 --- /dev/null +++ b/S2OJ/1256/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ab79b1c2d073d9bfbd7fa87564f18884ef477c51b10000d395872b3a9d6f398 +size 23 diff --git a/S2OJ/1256/data/data4.out b/S2OJ/1256/data/data4.out new file mode 100644 index 00000000..a4d51d64 --- /dev/null +++ b/S2OJ/1256/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7a33ec2d3fa6748259d5a72ed976b7308fa7355fd99818bc0dc12fece595277 +size 4 diff --git a/S2OJ/1256/data/data5.in b/S2OJ/1256/data/data5.in new file mode 100644 index 00000000..ec3736c1 --- /dev/null +++ b/S2OJ/1256/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b23e8d5a816485b054ebd690083ef8c03b20594b27ce786b01f885fb864dd14 +size 270 diff --git a/S2OJ/1256/data/data5.out b/S2OJ/1256/data/data5.out new file mode 100644 index 00000000..782152e7 --- /dev/null +++ b/S2OJ/1256/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0607b67fc074bbafc2cd17cfc7deec6df70d0658c62c03174dadf9184416309 +size 8 diff --git a/S2OJ/1256/data/data6.in b/S2OJ/1256/data/data6.in new file mode 100644 index 00000000..89c365ab --- /dev/null +++ b/S2OJ/1256/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55ba35365f40c37510f4be52509e3f2db65b6cc97878bef64bdac35661814949 +size 1676 diff --git a/S2OJ/1256/data/data6.out b/S2OJ/1256/data/data6.out new file mode 100644 index 00000000..12274597 --- /dev/null +++ b/S2OJ/1256/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd90834b6094e59435f119721b87ee4dd950bd7dc3dd63c967bafc1a487349a3 +size 7 diff --git a/S2OJ/1256/data/data7.in b/S2OJ/1256/data/data7.in new file mode 100644 index 00000000..8b42937e --- /dev/null +++ b/S2OJ/1256/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a8f786924b292bf956fcea4cc544177dfcf29970747f09d44df764562c4a171 +size 33252 diff --git a/S2OJ/1256/data/data7.out b/S2OJ/1256/data/data7.out new file mode 100644 index 00000000..e0761da9 --- /dev/null +++ b/S2OJ/1256/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2f7381fda4120a7eec8b5b60d09715d79e32bb78f4671a225ab9d7d10b2bf0b +size 6 diff --git a/S2OJ/1256/data/data8.in b/S2OJ/1256/data/data8.in new file mode 100644 index 00000000..6317e305 --- /dev/null +++ b/S2OJ/1256/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69328d98d73d11b5a7517bc57489f37ea3e4b2ee90f3fa4b1892047fc4a85579 +size 53071 diff --git a/S2OJ/1256/data/data8.out b/S2OJ/1256/data/data8.out new file mode 100644 index 00000000..f4d6262c --- /dev/null +++ b/S2OJ/1256/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3f3d5ea71f33b42b68ccbf7186cd8d5db06fc999652c8134014369386cd6db2 +size 10 diff --git a/S2OJ/1256/data/data9.in b/S2OJ/1256/data/data9.in new file mode 100644 index 00000000..848f2a4e --- /dev/null +++ b/S2OJ/1256/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c87e70f33804a3741999c2f2c24853d8796fd15b0b07795eafc8622d39f33a57 +size 132952 diff --git a/S2OJ/1256/data/data9.out b/S2OJ/1256/data/data9.out new file mode 100644 index 00000000..fa2a2584 --- /dev/null +++ b/S2OJ/1256/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed40c789ce92daa1a6d26d0cff0dd96891a7850c1c992b74fe0cb9cc77e87e7a +size 9