标签:c++ pre line 快速 面积 一个 continue dig 第一个
应动动要求,回cnblogs发篇博客。
#include <bits/stdc++.h> const int D = 1e9 + 7; int n, c[2510], pos[2510][2510]; bool used[2510]; struct Bit { int t[2510]; void add(int x, int d) { for (; x <= 2510; x += x & -x) t[x] += d; } int ask(int x) { int ret = 0; for (; x; x -= x & -x) ret += t[x]; return ret; } void clear() { for (int i = 1; i <= 2510; ++i) t[i] = 0; } } siz, len; inline int read() { int a = 0, b = 0; char c = getchar(); while (!isdigit(c)) b = c == ‘-‘ ? 1 : 0, c = getchar(); while (isdigit(c)) a = a * 10 + c - ‘0‘, c = getchar(); return b ? -a : a; } void modify(int x) { if (!used[x]) { used[x] = true; siz.add(x, 1), len.add(x, x); } } signed main() { n = read(); for (int i = 1, x, y; i <= n; ++i) x = read(), y = read(), pos[x][++c[x]] = y; for (int i = 1; i <= 2500; ++i) std::sort(pos[i] + 1, pos[i] + 1 + c[i]), pos[i][c[i] + 1] = 2501; long long ans = 0; for (int i = 1; i <= 2500; ++i) { if (!c[i]) continue; siz.clear(), len.clear(); for (int j = 1; j 2500; ++j) used[j] = false; for (int j = 1; j <= c[i]; ++j) modify(pos[i][j]); for (int j = i - 1; j; --j) { if (!c[j]) continue; int p1 = 1, p2 = 1, cur = std::max(pos[i][1], pos[j][1]); for (int k = 1; k <= c[j]; ++k) modify(pos[j][k]); while (pos[i][p1 + 1] <= cur) ++p1; while (pos[j][p2 + 1] <= cur) ++p2; while (p1 <= c[i] && p2 <= c[j]) { int mn = std::min(pos[i][p1], pos[j][p2]); int trend = std::min(pos[i][p1 + 1], pos[j][p2 + 1]); (ans += (long long) (i - j) * ((long long) (len.ask(trend - 1) - len.ask(cur - 1)) * siz.ask(mn) - (long long) (siz.ask(trend - 1) - siz.ask(cur - 1)) * len.ask(mn))) %= D; cur = trend; if (pos[i][p1 + 1] <= cur) ++p1; if (pos[j][p2 + 1] <= cur) ++p2; } } } return !printf("%lld\n", ans); }
标签:c++ pre line 快速 面积 一个 continue dig 第一个
原文地址:https://www.cnblogs.com/gekoo/p/11617567.html