From 8a47dddab2e7f2bd2d15346a1992bfa60206594f Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Wed, 6 Aug 2025 18:54:54 -0600 Subject: [PATCH 1/2] move deque_op to single file --- library/data_structures/deque_op/deque.hpp | 14 --------- library/data_structures/deque_op/index.hpp | 4 --- .../queue_only.hpp => uncommon/deque_op.hpp} | 29 ++++++++++++++----- .../data_structures/deque.test.cpp | 2 +- .../data_structures/deque_op.test.cpp | 2 +- .../deque_sliding_window.test.cpp | 2 +- 6 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 library/data_structures/deque_op/deque.hpp delete mode 100644 library/data_structures/deque_op/index.hpp rename library/data_structures/{deque_op/queue_only.hpp => uncommon/deque_op.hpp} (79%) diff --git a/library/data_structures/deque_op/deque.hpp b/library/data_structures/deque_op/deque.hpp deleted file mode 100644 index 268e5e45..00000000 --- a/library/data_structures/deque_op/deque.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -void push_front(T elem) { - l.push_back( - {elem, empty(l) ? elem : op(elem, l.back()[1])}); -} -void pop_back() { - if (empty(r)) { - vector a(sz(l)); - transform(all(l), rbegin(a), - [](dt& x) { return x[0]; }); - rebuild(a, sz(a) / 2); - } - r.pop_back(); -} diff --git a/library/data_structures/deque_op/index.hpp b/library/data_structures/deque_op/index.hpp deleted file mode 100644 index 045c5e96..00000000 --- a/library/data_structures/deque_op/index.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -T operator[](int i) { - return (i < sz(l) ? l[sz(l) - i - 1] : r[i - sz(l)])[0]; -} diff --git a/library/data_structures/deque_op/queue_only.hpp b/library/data_structures/uncommon/deque_op.hpp similarity index 79% rename from library/data_structures/deque_op/queue_only.hpp rename to library/data_structures/uncommon/deque_op.hpp index fe07169e..43d17176 100644 --- a/library/data_structures/deque_op/queue_only.hpp +++ b/library/data_structures/uncommon/deque_op.hpp @@ -17,9 +17,30 @@ template struct deq { if (empty(r)) return l.back()[1]; return op(l.back()[1], r.back()[1]); } - int siz() { return sz(l) + sz(r); } + T operator[](int i) { + return ( + i < sz(l) ? l[sz(l) - i - 1] : r[i - sz(l)])[0]; + } T front() { return (empty(l) ? r[0] : l.back())[0]; } T back() { return (empty(r) ? l[0] : r.back())[0]; } + int siz() { return sz(l) + sz(r); } + void push_back(T elem) { + r.push_back( + {elem, empty(r) ? elem : op(r.back()[1], elem)}); + } + void pop_back() { + if (empty(r)) { + vector a(sz(l)); + transform(all(l), rbegin(a), + [](dt& x) { return x[0]; }); + rebuild(a, sz(a) / 2); + } + r.pop_back(); + } + void push_front(T elem) { + l.push_back( + {elem, empty(l) ? elem : op(elem, l.back()[1])}); + } void pop_front() { if (empty(l)) { vector a(sz(r)); @@ -29,10 +50,6 @@ template struct deq { } l.pop_back(); } - void push_back(T elem) { - r.push_back( - {elem, empty(r) ? elem : op(r.back()[1], elem)}); - } void rebuild(const vector& a, int sz_le) { vector presum(sz(a)); partial_sum(rend(a) - sz_le, rend(a), @@ -46,6 +63,4 @@ template struct deq { transform(sz_le + all(a), begin(presum) + sz_le, begin(r), [](T x, T y) { return dt{x, y}; }); } -#include "deque.hpp" -#include "index.hpp" }; diff --git a/tests/library_checker_aizu_tests/data_structures/deque.test.cpp b/tests/library_checker_aizu_tests/data_structures/deque.test.cpp index 9f9d0be8..30e25494 100644 --- a/tests/library_checker_aizu_tests/data_structures/deque.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/deque.test.cpp @@ -1,7 +1,7 @@ #define PROBLEM \ "https://onlinejudge.u-aizu.ac.jp/courses/lesson/8/ITP2/all/ITP2_1_B" #include "../template.hpp" -#include "../../../library/data_structures/deque_op/queue_only.hpp" +#include "../../../library/data_structures/uncommon/deque_op.hpp" int main() { cin.tie(0)->sync_with_stdio(0); int q; diff --git a/tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp b/tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp index a43f9e19..91d0e21c 100644 --- a/tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp @@ -2,7 +2,7 @@ "https://judge.yosupo.jp/problem/deque_operate_all_composite" #include "../template.hpp" #include "../../../library/contest/random.hpp" -#include "../../../library/data_structures/deque_op/queue_only.hpp" +#include "../../../library/data_structures/uncommon/deque_op.hpp" int main() { cin.tie(0)->sync_with_stdio(0); const int mod = 998'244'353; diff --git a/tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp b/tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp index 5d0a371a..193d272c 100644 --- a/tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp +++ b/tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp @@ -1,7 +1,7 @@ #define PROBLEM \ "https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_3_D" #include "../template.hpp" -#include "../../../library/data_structures/deque_op/queue_only.hpp" +#include "../../../library/data_structures/uncommon/deque_op.hpp" int mn(int x, int y) { return min(x, y); } int main() { cin.tie(0)->sync_with_stdio(0); From 61a54589dfe714e49df151fb5ccc94e9f44cc79c Mon Sep 17 00:00:00 2001 From: Luke Videckis Date: Wed, 6 Aug 2025 18:55:28 -0600 Subject: [PATCH 2/2] not include it in PDF either --- tests/scripts/build_pdf.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/build_pdf.sh b/tests/scripts/build_pdf.sh index c9128e33..192f3ce7 100755 --- a/tests/scripts/build_pdf.sh +++ b/tests/scripts/build_pdf.sh @@ -18,6 +18,7 @@ rm ../library/data_structures/seg_tree_uncommon/implicit.hpp || exit 1 rm ../library/data_structures/seg_tree_uncommon/kth_smallest_query.hpp || exit 1 rm ../library/data_structures/uncommon/mode_query.hpp || exit 1 rm ../library/data_structures/uncommon/priority_queue_of_updates.hpp || exit 1 +rm ../library/data_structures/uncommon/deque_op.hpp || exit 1 rm ../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp || exit 1 rm ../library/graphs/strongly_connected_components/offline_incremental_scc.hpp || exit 1 rm ../library/graphs/uncommon/bridges.hpp || exit 1