pub struct DequeAggregation<M>where
M: Monoid,{
front_stack: Vec<(M::T, M::T)>,
back_stack: Vec<(M::T, M::T)>,
}Fields§
§front_stack: Vec<(M::T, M::T)>§back_stack: Vec<(M::T, M::T)>Implementations§
Source§impl<M> DequeAggregation<M>where
M: Monoid,
impl<M> DequeAggregation<M>where
M: Monoid,
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 20)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn fold_all(&self) -> M::T
pub fn fold_all(&self) -> M::T
Examples found in repository?
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 37)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}pub fn front(&self) -> Option<&M::T>
pub fn back(&self) -> Option<&M::T>
Sourcepub fn push_front(&mut self, value: M::T)
pub fn push_front(&mut self, value: M::T)
Examples found in repository?
crates/competitive/src/data_structure/sliding_window_aggregation.rs (line 193)
188 pub fn pop_front(&mut self) -> Option<M::T> {
189 if self.front_stack.is_empty() {
190 let n = self.back_stack.len();
191 let mut back_stack = std::mem::take(&mut self.back_stack);
192 for x in back_stack.drain(..n.div_ceil(2)).map(|t| t.1).rev() {
193 self.push_front(x);
194 }
195 for x in back_stack.drain(..).map(|t| t.1) {
196 self.push_back(x);
197 }
198 }
199 self.front_stack.pop().map(|t| t.1)
200 }
201 pub fn pop_back(&mut self) -> Option<M::T> {
202 if self.back_stack.is_empty() {
203 let n = self.front_stack.len();
204 let mut front_stack = std::mem::take(&mut self.front_stack);
205 for x in front_stack.drain(..n.div_ceil(2)).map(|t| t.1).rev() {
206 self.push_back(x);
207 }
208 for x in front_stack.drain(..).map(|t| t.1) {
209 self.push_front(x);
210 }
211 }
212 self.back_stack.pop().map(|t| t.1)
213 }More examples
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 25)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}Sourcepub fn push_back(&mut self, value: M::T)
pub fn push_back(&mut self, value: M::T)
Examples found in repository?
crates/competitive/src/data_structure/sliding_window_aggregation.rs (line 196)
188 pub fn pop_front(&mut self) -> Option<M::T> {
189 if self.front_stack.is_empty() {
190 let n = self.back_stack.len();
191 let mut back_stack = std::mem::take(&mut self.back_stack);
192 for x in back_stack.drain(..n.div_ceil(2)).map(|t| t.1).rev() {
193 self.push_front(x);
194 }
195 for x in back_stack.drain(..).map(|t| t.1) {
196 self.push_back(x);
197 }
198 }
199 self.front_stack.pop().map(|t| t.1)
200 }
201 pub fn pop_back(&mut self) -> Option<M::T> {
202 if self.back_stack.is_empty() {
203 let n = self.front_stack.len();
204 let mut front_stack = std::mem::take(&mut self.front_stack);
205 for x in front_stack.drain(..n.div_ceil(2)).map(|t| t.1).rev() {
206 self.push_back(x);
207 }
208 for x in front_stack.drain(..).map(|t| t.1) {
209 self.push_front(x);
210 }
211 }
212 self.back_stack.pop().map(|t| t.1)
213 }More examples
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 28)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}Sourcepub fn pop_front(&mut self) -> Option<M::T>
pub fn pop_front(&mut self) -> Option<M::T>
Examples found in repository?
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 31)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}Sourcepub fn pop_back(&mut self) -> Option<M::T>
pub fn pop_back(&mut self) -> Option<M::T>
Examples found in repository?
crates/library_checker/src/data_structure/deque_operate_all_composite.rs (line 34)
17pub fn deque_operate_all_composite(reader: impl Read, writer: impl Write) {
18 prepare_io!(reader, writer);
19 sc!(q);
20 let mut deq = DequeAggregation::<LinearOperation<_>>::new();
21 for _ in 0..q {
22 sc!(query: Query);
23 match query {
24 Query::PushFront { ab } => {
25 deq.push_front(ab);
26 }
27 Query::PushBack { ab } => {
28 deq.push_back(ab);
29 }
30 Query::PopFront => {
31 deq.pop_front();
32 }
33 Query::PopBack => {
34 deq.pop_back();
35 }
36 Query::Apply { x } => {
37 let (a, b) = deq.fold_all();
38 pp!(a * x + b);
39 }
40 }
41 }
42}Trait Implementations§
Source§impl<M> Clone for DequeAggregation<M>where
M: Monoid,
impl<M> Clone for DequeAggregation<M>where
M: Monoid,
Source§impl<M> Debug for DequeAggregation<M>
impl<M> Debug for DequeAggregation<M>
Auto Trait Implementations§
impl<M> Freeze for DequeAggregation<M>
impl<M> RefUnwindSafe for DequeAggregation<M>
impl<M> Send for DequeAggregation<M>
impl<M> Sync for DequeAggregation<M>
impl<M> Unpin for DequeAggregation<M>
impl<M> UnsafeUnpin for DequeAggregation<M>
impl<M> UnwindSafe for DequeAggregation<M>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more