版本比较
题解:P6235 [eJOI 2019] 矩形染色
正文
增加 5 行删除 5 行
58 行未改动5960616263636465666718 行未改动8687888990909192939495969797989910010128 行未改动13013113213313413413513613713813914014114114214314414536 行未改动58 行未改动 inline ll ask(int x) {ll _ = 0; for (int i = x; i; i -= i & -i) _ += bit[i]; return _;} }; struct SegT { ll mx1[N << 2], mx2[N << 2]; SegT() {REQ(i, 0, (N << 2)) mx1[i] = mx2[i] = -inf;} SegT() {REQ(i, 0, (N << 2)) mx1[i] = mx2[i] = -inf;}#define ls(x) (x << 1)#define rs(x) (x << 1 | 1) inline void pushup(int x) {mx1[x] = std::max(mx1[ls(x)], mx1[rs(x)]), mx2[x] = std::max(mx2[ls(x)], mx2[rs(x)]);} inline void update(int x, int l, int r, int now, ll c1, ll c2) {18 行未改动 return c; } }; struct Chenzhaoxu { int n, m, p[N]; ll a[N], f[N], g[N], As, Rs; int n, m, p[N]; ll a[N], f[N], g[N], As, Rs; Seg c[N]; bool vis[N]; fenwick TOT; SegT T; inline ll S(int l, int r) {return a[r] - a[l - 1];} inline ll solve(const std::vector<int>& array, const std::vector<Seg>& opera) { n = array.size(), m = opera.size(), As = 0, Rs = 0; REQ(i, 0, n) a[i + 1] = array[i], a[i + 1] += a[i]; REQ(i, 0, m) c[i + 1] = opera[i], As += c[i + 1].w; int len = -1, L = 1, R = 1; // bound of BLACK PART, [1,L) is RED, (R,m] is BLUE. int len = -1, L = 1, R = 1; // bound of BLACK PART, [1,L) is RED, (R,m] is BLUE. REP(i, 1, m) { if (len < c[i].r - c[i].l) len = c[i].r - c[i].l, L = R = i; else if (len == c[i].r - c[i].l) R = i; }28 行未改动 std::reverse(wB + 2, wB + n + m + 1); std::swap(wA, wB); } std::vector<int> arr1, arr2; if (m & 1) {REP(i, 2, n + m) if (i & 1) arr2.emplace_back(wB[i]); else arr1.emplace_back(wB[i]);} if (m & 1) {REP(i, 2, n + m) if (i & 1) arr2.emplace_back(wB[i]); else arr1.emplace_back(wB[i]);} else {REP(i, 2, n + m) if (i & 1) arr1.emplace_back(wB[i]); else arr2.emplace_back(wB[i]);} std::vector<Seg> o1, o2; REP(i, 2, n + m) { int Sx = std::max(1, i - m), Sy = i - Sx; int Ty = std::max(1, i - n), Tx = i - Ty; if (i & 1) o2.emplace_back((Seg) {(Sx + m - Sy + 1) / 2, (Tx + m - Ty + 1) / 2, wA[i]}); else o1.emplace_back((Seg) {(Sx + m - Sy + 1) / 2, (Tx + m - Ty + 1) / 2, wA[i]}); else o1.emplace_back((Seg) {(Sx + m - Sy + 1) / 2, (Tx + m - Ty + 1) / 2, wA[i]}); } jyt << (T1.solve(arr1, o1) + T2.solve(arr2, o2)) << '\n'; return 0; }36 行未改动