Skip to content

Commit 8075a0d

Browse files
authored
Deque op nits (#157)
* move deque_op to single file * not include it in PDF either
1 parent 1f294c0 commit 8075a0d

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

library/data_structures/deque_op/deque.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

library/data_structures/deque_op/index.hpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

library/data_structures/deque_op/queue_only.hpp renamed to library/data_structures/uncommon/deque_op.hpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,30 @@ template<class T, class F> struct deq {
1717
if (empty(r)) return l.back()[1];
1818
return op(l.back()[1], r.back()[1]);
1919
}
20-
int siz() { return sz(l) + sz(r); }
20+
T operator[](int i) {
21+
return (
22+
i < sz(l) ? l[sz(l) - i - 1] : r[i - sz(l)])[0];
23+
}
2124
T front() { return (empty(l) ? r[0] : l.back())[0]; }
2225
T back() { return (empty(r) ? l[0] : r.back())[0]; }
26+
int siz() { return sz(l) + sz(r); }
27+
void push_back(T elem) {
28+
r.push_back(
29+
{elem, empty(r) ? elem : op(r.back()[1], elem)});
30+
}
31+
void pop_back() {
32+
if (empty(r)) {
33+
vector<T> a(sz(l));
34+
transform(all(l), rbegin(a),
35+
[](dt& x) { return x[0]; });
36+
rebuild(a, sz(a) / 2);
37+
}
38+
r.pop_back();
39+
}
40+
void push_front(T elem) {
41+
l.push_back(
42+
{elem, empty(l) ? elem : op(elem, l.back()[1])});
43+
}
2344
void pop_front() {
2445
if (empty(l)) {
2546
vector<T> a(sz(r));
@@ -29,10 +50,6 @@ template<class T, class F> struct deq {
2950
}
3051
l.pop_back();
3152
}
32-
void push_back(T elem) {
33-
r.push_back(
34-
{elem, empty(r) ? elem : op(r.back()[1], elem)});
35-
}
3653
void rebuild(const vector<T>& a, int sz_le) {
3754
vector<T> presum(sz(a));
3855
partial_sum(rend(a) - sz_le, rend(a),
@@ -46,6 +63,4 @@ template<class T, class F> struct deq {
4663
transform(sz_le + all(a), begin(presum) + sz_le,
4764
begin(r), [](T x, T y) { return dt{x, y}; });
4865
}
49-
#include "deque.hpp"
50-
#include "index.hpp"
5166
};

tests/library_checker_aizu_tests/data_structures/deque.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#define PROBLEM \
22
"https://onlinejudge.u-aizu.ac.jp/courses/lesson/8/ITP2/all/ITP2_1_B"
33
#include "../template.hpp"
4-
#include "../../../library/data_structures/deque_op/queue_only.hpp"
4+
#include "../../../library/data_structures/uncommon/deque_op.hpp"
55
int main() {
66
cin.tie(0)->sync_with_stdio(0);
77
int q;

tests/library_checker_aizu_tests/data_structures/deque_op.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"https://judge.yosupo.jp/problem/deque_operate_all_composite"
33
#include "../template.hpp"
44
#include "../../../library/contest/random.hpp"
5-
#include "../../../library/data_structures/deque_op/queue_only.hpp"
5+
#include "../../../library/data_structures/uncommon/deque_op.hpp"
66
int main() {
77
cin.tie(0)->sync_with_stdio(0);
88
const int mod = 998'244'353;

tests/library_checker_aizu_tests/data_structures/deque_sliding_window.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#define PROBLEM \
22
"https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_3_D"
33
#include "../template.hpp"
4-
#include "../../../library/data_structures/deque_op/queue_only.hpp"
4+
#include "../../../library/data_structures/uncommon/deque_op.hpp"
55
int mn(int x, int y) { return min(x, y); }
66
int main() {
77
cin.tie(0)->sync_with_stdio(0);

tests/scripts/build_pdf.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rm ../library/data_structures/seg_tree_uncommon/implicit.hpp || exit 1
1818
rm ../library/data_structures/seg_tree_uncommon/kth_smallest_query.hpp || exit 1
1919
rm ../library/data_structures/uncommon/mode_query.hpp || exit 1
2020
rm ../library/data_structures/uncommon/priority_queue_of_updates.hpp || exit 1
21+
rm ../library/data_structures/uncommon/deque_op.hpp || exit 1
2122
rm ../library/graphs/strongly_connected_components/add_edges_strongly_connected.hpp || exit 1
2223
rm ../library/graphs/strongly_connected_components/offline_incremental_scc.hpp || exit 1
2324
rm ../library/graphs/uncommon/bridges.hpp || exit 1

0 commit comments

Comments
 (0)