版本比较
面积并 & 周长并复习笔记
正文
增加 10 行删除 10 行
75 行未改动76777879808182838456 行未改动14114214314414514614714814915015142 行未改动19419519619719819920020120218 行未改动22122222322422522622722822939 行未改动26927027127227327427527627727832 行未改动31131231331431531631731831932032132232332432532632735 行未改动36336436536636736836975 行未改动mp.add(x1), mp.add(x2);}mp(), sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int res = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= 2 * n; i++) {56 行未改动auto solve = [&](line* a) -> void {build();stable_sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.pos == b.pos) return a.type > b.type;return a.pos < b.pos;});for (int i = 1, last = 0; i <= 2 * n; i++) {update(mp[a[i].l], mp[a[i].r] - 1, a[i].type);res += abs(val[1] - last), last = val[1];}};42 行未改动}int scan() {mp(), sort(a + 1, a + cnt + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int res = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= cnt; i++) {18 行未改动for (auto [b, x1, x2] : D0) {res += x2 - x1 + 1;for (auto [y, x3, x4] : H) {int x = y - b;if (x1 <= x && x <= x2 && x3 <= x && x <= x4) p.emplace_back(x, y);}for (auto [x, y1, y2] : V) {int y = x + b;if (x1 <= x && x <= x2 && y1 <= y && y <= y2) p.emplace_back(x, y);39 行未改动记区间长度为 $l$,我们有:- 若 $w=0$,$l_0,l_1$ 直接由左右儿子转移。- 若 $w$ 为奇,此时我们需要排除 $0$ 的干扰。这里我们需要仔细分析原本的 $l_1,l_2$,以及通过左右儿子转移的量中 $0$ 的贡献。这些讨论并不复杂,但过于繁杂,这里略去。结果为:$l_2$ 由左右儿子转移,$l_1 \gets l-l_2$。- 若 $w$ 为偶,同理可得 $l_1$ 由左右儿子转移,$l_2 \gets l-l_1$。然后正常扫描线,复杂度 $O(n \log n)$。32 行未改动mp.add(x1), mp.add(x2);}mp(), sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int r1 = 0, r2 = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= 2 * n; i++) {r1 += (a[i].y - a[i - 1].y) * l1[1], r2 += (a[i].y - a[i - 1].y) * l2[1];update(mp[a[i].x1], mp[a[i].x2] - 1, a[i].type);} cout << r1 << '\n' << r2;}```::::## [P3997 [SHOI2013] 扇形面积并](https://www.luogu.com.cn/problem/P3997)35 行未改动}int len = st.size();if (len >= k) res += 1LL * st[len - k] * st[len - k];} cout << res;}```::::75 行未改动76777879808182838456 行未改动14114214314414514614714814915015142 行未改动19419519619719819920020120218 行未改动22122222322422522622722822939 行未改动26927027127227327427527627727832 行未改动31131231331431531631731831932032132232332432532632735 行未改动36336436536636736836975 行未改动mp.add(x1), mp.add(x2);}mp(), sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int res = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= 2 * n; i++) {56 行未改动auto solve = [&](line* a) -> void {build();stable_sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.pos == b.pos) return a.type > b.type;return a.pos < b.pos;});for (int i = 1, last = 0; i <= 2 * n; i++) {update(mp[a[i].l], mp[a[i].r] - 1, a[i].type);res += abs(val[1] - last), last = val[1];}};42 行未改动}int scan() {mp(), sort(a + 1, a + cnt + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int res = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= cnt; i++) {18 行未改动for (auto [b, x1, x2] : D0) {res += x2 - x1 + 1;for (auto [y, x3, x4] : H) {int x = y - b;if (x1 <= x && x <= x2 && x3 <= x && x <= x4) p.emplace_back(x, y);}for (auto [x, y1, y2] : V) {int y = x + b;if (x1 <= x && x <= x2 && y1 <= y && y <= y2) p.emplace_back(x, y);39 行未改动记区间长度为 $l$,我们有:- 若 $w=0$,$l_0,l_1$ 直接由左右儿子转移。- 若 $w$ 为奇,此时我们需要排除 $0$ 的干扰。这里我们需要仔细分析原本的 $l_1,l_2$,以及通过左右儿子转移的量中 $0$ 的贡献。这些讨论并不复杂,但过于繁杂,这里略去。结果为:$l_2$ 由左右儿子转移,$l_1 \gets l-l_2$。- 若 $w$ 为偶,同理可得 $l_1$ 由左右儿子转移,$l_2 \gets l-l_1$。然后正常扫描线,复杂度 $O(n \log n)$。32 行未改动mp.add(x1), mp.add(x2);}mp(), sort(a + 1, a + 2 * n + 1, [](const line& a, const line& b) -> bool {if (a.y == b.y) return a.type > b.type;return a.y < b.y;});int r1 = 0, r2 = 0;update(mp[a[1].x1], mp[a[1].x2] - 1, a[1].type);for (int i = 2; i <= 2 * n; i++) {r1 += (a[i].y - a[i - 1].y) * l1[1], r2 += (a[i].y - a[i - 1].y) * l2[1];update(mp[a[i].x1], mp[a[i].x2] - 1, a[i].type);} cout << r1 << '\n' << r2;}```::::## [P3997 [SHOI2013] 扇形面积并](https://www.luogu.com.cn/problem/P3997)35 行未改动}int len = st.size();if (len >= k) res += 1LL * st[len - k] * st[len - k];} cout << res;}```::::