正文
增加 60 行删除 60 行
123456784 行未改动9293949596979899100101102103104105106107108109183 行未改动全部展开29329429529629729829930030113 行未改动31531631731831932032132232395 行未改动41942042142242342442542642717 行未改动4454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804813 行未改动485486487488489490491492493494495496497498499119 行未改动全部展开61962062162262362462562662762862963063163263363463563658 行未改动6956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247253 行未改动729730731732733734735736737738739740741742147 行未改动全部展开89089189289389489589689789868 行未改动96796896997097197297397497510 行未改动9869879889899909919929939949959969979989991000100160 行未改动10621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141## 前言你说什么?问我为什么要写这依托东西?就是纯闲的此处给出了题解区的没提到过的做法,而且亲测每种做法都能过,不能过的话踢我()84 行未改动}int main() {int a = read(), b = read();odt.insert(Node(0, 1e9, 0));assign(0, 0, a);assign(1, 1, b);assign(0, 1, a + b);auto it = odt.lower_bound(Node(0));out(it->v);return 0;}```183 行未改动全部展开struct Matrix {int a, b, c, d;Matrix(int a = 1, int b = 0, int c = 0, int d = 1) : a(a), b(b), c(c), d(d) {}inline Matrix operator*(const Matrix &other) const {return Matrix(a * other.a + b * other.c,a * other.b + b * other.d,13 行未改动int dp1 = MA.a * dp0 + MA.b * one;int dp2 = MB.a * dp1 + MB.b * one;out(dp2);return 0;}```95 行未改动int rebuild(int l, int r, int dim) {if (l > r) return 0;int mid = (l + r) >> 1, u = new_node();nth_element(pt + l, pt + mid, pt + r + 1,[dim](const Point &a, const Point &b) {return a.x[dim] < b.x[dim];});tr[u].p = pt[mid];17 行未改动tr[u].p = p;push_up(u);return;}if (p.x[dim] <= tr[u].p.x[dim])insert(tr[u].l, p, dim ^ 1);elseinsert(tr[u].r, p, dim ^ 1);push_up(u);maintain(u, dim);}inline bool in_range(const Node &t, int x1, int y1, int x2, int y2) {return t.L[0] >= x1 && t.R[0] <= x2 &&t.L[1] >= y1 && t.R[1] <= y2;}inline bool point_in(const Point &t, int x1, int y1, int x2, int y2) {return t.x[0] >= x1 && t.x[0] <= x2 &&t.x[1] >= y1 && t.x[1] <= y2;}inline bool out_range(const Node &t, int x1, int y1, int x2, int y2) {return t.R[0] < x1 || t.L[0] > x2 ||t.R[1] < y1 || t.L[1] > y2;}int query(int u, int x1, int y1, int x2, int y2) {if (!u) return 0;if (in_range(tr[u], x1, y1, x2, y2)) return tr[u].sum;if (out_range(tr[u], x1, y1, x2, y2)) return 0;int res = 0;if (point_in(tr[u].p, x1, y1, x2, y2))res += tr[u].p.w;res += query(tr[u].l, x1, y1, x2, y2);res += query(tr[u].r, x1, y1, x2, y2);return res;3 行未改动tr[0].L[0] = tr[0].L[1] = INF;tr[0].R[0] = tr[0].R[1] = -INF;int a = read(), b = read();insert(rt, {a, 0, a}, 0);insert(rt, {0, b, b}, 0);int sum = query(rt, -INF, -INF, INF, INF);out(sum);return 0;}```119 行未改动全部展开}int main() {int a = read(), b = read();vector<Point> points;points.emplace_back(a, 0);points.emplace_back(-b, 0);int minDistSq = closestPair(points);int sum = sqrt(minDistSq);out(sum);return 0;}```58 行未改动inline double calc(const function<double(double)>& f, double a, double b, int n = 1000) {double h = (b - a) / n;double sum = f(a) + f(b);for (int i = 1; i < n; i += 2) {sum += 4.0 * f(a + i * h);}for (int i = 2; i < n; i += 2) {sum += 2.0 * f(a + i * h);}return sum * h / 3.0;}int main() {int a = read(), b = read();auto func = [a, b](double x) {return static_cast<double>(a + b);};double res = calc(func, 0.0, 1.0);int rres = static_cast<int>(round(res));out(rres);return 0;}```3 行未改动设变量为x和y,表示a和b的值。我们需要最大化x+y,同时约束x=a和y=b。将A+B问题建模为线性规划:最大化 x + y约束: x = a, y = b转换为标准形式:最大化 x + y约束: x ≤ a, -x ≤ -ay ≤ b, -y ≤ -b代码如下:``` cpp// Ciallo~(∠・ω< )⌒★147 行未改动全部展开{0.0, 1.0}, // y ≤ b{0.0, -1.0} // -y ≤ -b};vector<double> B = {static_cast<double>(a), static_cast<double>(-a),static_cast<double>(b), static_cast<double>(-b)};vector<double> C = {1.0, 1.0};SimplexSolver solver(A, B, C);68 行未改动#define debug(x) cout << #x << " = " << (x) << endlclass GeFunc {private:vi vec;public:explicit GeFunc(int value = 0) {vec.push_back(value);}10 行未改动};int main() {int a = read(), b = read();GeFunc gf1(a);GeFunc gf2(b);GeFunc sum = gf1 + gf2;out(sum.get());return 0;}```60 行未改动#define lowbit(x) ((x) & (-(x)))#define debug(x) cout << #x << " = " << (x) << endlstruct DCTNode {int l, r;int val;bool is;DCTNode *left, *right;DCTNode(int l, int r, int val, bool is): l(l), r(r), val(val), is(is), left(nullptr), right(nullptr) {}};class DecompositionTree {private:DCTNode* root;vi data;DCTNode* build(int l, int r) {if (l == r) {return new DCTNode(l, r, data[l], false);}int mid = (l + r) >> 1;DCTNode* left = build(l, mid);DCTNode* right = build(mid + 1, r);int sum = left->val + right->val;DCTNode* node = new DCTNode(l, r, sum, true);node->left = left;node->right = right;return node;}void destroy(DCTNode* node) {if (!node) return;destroy(node->left);destroy(node->right);delete node;}public:explicit DecompositionTree(const vi& arr) : data(arr) {root = arr.empty() ? nullptr : build(0, (int)arr.size() - 1);}~DecompositionTree() {destroy(root);}inline int get_sum() const {return root ? root->val : 0;}void print_tr(DCTNode* node, int indent = 0) const {if (!node) return;for (int i = 0; i < indent; ++i) putchar(' ');printf("[%d,%d]: %d", node->l, node->r, node->val);if (node->is) printf(" (Merge)");putchar('\n');print_tr(node->left, indent + 4);print_tr(node->right, indent + 4);}inline DCTNode* get_root() const { return root; }};int main() {int a = read(), b = read();vi arr = {a, b};DecompositionTree dt(arr);out(dt.get_sum());return 0;}```123456784 行未改动9293949596979899100101102103104105106107108109183 行未改动全部展开29329429529629729829930030113 行未改动31531631731831932032132232395 行未改动41942042142242342442542642717 行未改动4454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804813 行未改动485486487488489490491492493494495496497498499119 行未改动全部展开61962062162262362462562662762862963063163263363463563658 行未改动6956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247253 行未改动729730731732733734735736737738739740741742147 行未改动全部展开89089189289389489589689789868 行未改动96796896997097197297397497510 行未改动9869879889899909919929939949959969979989991000100160 行未改动10621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141## 前言你说什么?问我为什么要写这依托东西?就是纯闲的此处给出了题解区的没提到过的做法,而且亲测每种做法都能过,不能过的话踢我()84 行未改动}int main() {int a = read(), b = read();odt.insert(Node(0, 1e9, 0));assign(0, 0, a);assign(1, 1, b);assign(0, 1, a + b);auto it = odt.lower_bound(Node(0));out(it->v);return 0;}```183 行未改动全部展开struct Matrix {int a, b, c, d;Matrix(int a = 1, int b = 0, int c = 0, int d = 1) : a(a), b(b), c(c), d(d) {}inline Matrix operator*(const Matrix &other) const {return Matrix(a * other.a + b * other.c,a * other.b + b * other.d,13 行未改动int dp1 = MA.a * dp0 + MA.b * one;int dp2 = MB.a * dp1 + MB.b * one;out(dp2);return 0;}```95 行未改动int rebuild(int l, int r, int dim) {if (l > r) return 0;int mid = (l + r) >> 1, u = new_node();nth_element(pt + l, pt + mid, pt + r + 1,[dim](const Point &a, const Point &b) {return a.x[dim] < b.x[dim];});tr[u].p = pt[mid];17 行未改动tr[u].p = p;push_up(u);return;}if (p.x[dim] <= tr[u].p.x[dim])insert(tr[u].l, p, dim ^ 1);elseinsert(tr[u].r, p, dim ^ 1);push_up(u);maintain(u, dim);}inline bool in_range(const Node &t, int x1, int y1, int x2, int y2) {return t.L[0] >= x1 && t.R[0] <= x2 &&t.L[1] >= y1 && t.R[1] <= y2;}inline bool point_in(const Point &t, int x1, int y1, int x2, int y2) {return t.x[0] >= x1 && t.x[0] <= x2 &&t.x[1] >= y1 && t.x[1] <= y2;}inline bool out_range(const Node &t, int x1, int y1, int x2, int y2) {return t.R[0] < x1 || t.L[0] > x2 ||t.R[1] < y1 || t.L[1] > y2;}int query(int u, int x1, int y1, int x2, int y2) {if (!u) return 0;if (in_range(tr[u], x1, y1, x2, y2)) return tr[u].sum;if (out_range(tr[u], x1, y1, x2, y2)) return 0;int res = 0;if (point_in(tr[u].p, x1, y1, x2, y2))res += tr[u].p.w;res += query(tr[u].l, x1, y1, x2, y2);res += query(tr[u].r, x1, y1, x2, y2);return res;3 行未改动tr[0].L[0] = tr[0].L[1] = INF;tr[0].R[0] = tr[0].R[1] = -INF;int a = read(), b = read();insert(rt, {a, 0, a}, 0);insert(rt, {0, b, b}, 0);int sum = query(rt, -INF, -INF, INF, INF);out(sum);return 0;}```119 行未改动全部展开}int main() {int a = read(), b = read();vector<Point> points;points.emplace_back(a, 0);points.emplace_back(-b, 0);int minDistSq = closestPair(points);int sum = sqrt(minDistSq);out(sum);return 0;}```58 行未改动inline double calc(const function<double(double)>& f, double a, double b, int n = 1000) {double h = (b - a) / n;double sum = f(a) + f(b);for (int i = 1; i < n; i += 2) {sum += 4.0 * f(a + i * h);}for (int i = 2; i < n; i += 2) {sum += 2.0 * f(a + i * h);}return sum * h / 3.0;}int main() {int a = read(), b = read();auto func = [a, b](double x) {return static_cast<double>(a + b);};double res = calc(func, 0.0, 1.0);int rres = static_cast<int>(round(res));out(rres);return 0;}```3 行未改动设变量为x和y,表示a和b的值。我们需要最大化x+y,同时约束x=a和y=b。将A+B问题建模为线性规划:最大化 x + y约束: x = a, y = b转换为标准形式:最大化 x + y约束: x ≤ a, -x ≤ -ay ≤ b, -y ≤ -b代码如下:``` cpp// Ciallo~(∠・ω< )⌒★147 行未改动全部展开{0.0, 1.0}, // y ≤ b{0.0, -1.0} // -y ≤ -b};vector<double> B = {static_cast<double>(a), static_cast<double>(-a),static_cast<double>(b), static_cast<double>(-b)};vector<double> C = {1.0, 1.0};SimplexSolver solver(A, B, C);68 行未改动#define debug(x) cout << #x << " = " << (x) << endlclass GeFunc {private:vi vec;public:explicit GeFunc(int value = 0) {vec.push_back(value);}10 行未改动};int main() {int a = read(), b = read();GeFunc gf1(a);GeFunc gf2(b);GeFunc sum = gf1 + gf2;out(sum.get());return 0;}```60 行未改动#define lowbit(x) ((x) & (-(x)))#define debug(x) cout << #x << " = " << (x) << endlstruct DCTNode {int l, r;int val;bool is;DCTNode *left, *right;DCTNode(int l, int r, int val, bool is): l(l), r(r), val(val), is(is), left(nullptr), right(nullptr) {}};class DecompositionTree {private:DCTNode* root;vi data;DCTNode* build(int l, int r) {if (l == r) {return new DCTNode(l, r, data[l], false);}int mid = (l + r) >> 1;DCTNode* left = build(l, mid);DCTNode* right = build(mid + 1, r);int sum = left->val + right->val;DCTNode* node = new DCTNode(l, r, sum, true);node->left = left;node->right = right;return node;}void destroy(DCTNode* node) {if (!node) return;destroy(node->left);destroy(node->right);delete node;}public:explicit DecompositionTree(const vi& arr) : data(arr) {root = arr.empty() ? nullptr : build(0, (int)arr.size() - 1);}~DecompositionTree() {destroy(root);}inline int get_sum() const {return root ? root->val : 0;}void print_tr(DCTNode* node, int indent = 0) const {if (!node) return;for (int i = 0; i < indent; ++i) putchar(' ');printf("[%d,%d]: %d", node->l, node->r, node->val);if (node->is) printf(" (Merge)");putchar('\n');print_tr(node->left, indent + 4);print_tr(node->right, indent + 4);}inline DCTNode* get_root() const { return root; }};int main() {int a = read(), b = read();vi arr = {a, b};DecompositionTree dt(arr);out(dt.get_sum());return 0;}```