Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Powerful_Array_Policy< T > Struct Template Reference

Policy: "powerful array" sum = sum(cnt[x]^2 * x). More...

#include <tpl_mo_algorithm.H>

Collaboration diagram for Aleph::Powerful_Array_Policy< T >:
[legend]

Public Types

using answer_type = long long
 

Public Member Functions

void init (const Array< T > &, size_t)
 
void add (const Array< T > &data, size_t idx)
 
void remove (const Array< T > &data, size_t idx)
 
answer_type answer () const
 

Public Attributes

MapOLhash< T, long longcnt
 
long long sum = 0
 

Detailed Description

template<typename T>
struct Aleph::Powerful_Array_Policy< T >

Policy: "powerful array" sum = sum(cnt[x]^2 * x).

For each element x in the current window with count c, the contribution is c^2 * x. We maintain the sum incrementally: add x: sum += (2*cnt+1)*x, then cnt++ remove x: cnt–, then sum -= (2*cnt+1)*x

Template Parameters
TElement type (must be hashable and arithmetic-like).

Definition at line 452 of file tpl_mo_algorithm.H.

Member Typedef Documentation

◆ answer_type

template<typename T >
using Aleph::Powerful_Array_Policy< T >::answer_type = long long

Definition at line 454 of file tpl_mo_algorithm.H.

Member Function Documentation

◆ add()

template<typename T >
void Aleph::Powerful_Array_Policy< T >::add ( const Array< T > &  data,
size_t  idx 
)
inline

◆ answer()

template<typename T >
answer_type Aleph::Powerful_Array_Policy< T >::answer ( ) const
inline

Definition at line 480 of file tpl_mo_algorithm.H.

References Aleph::Powerful_Array_Policy< T >::sum.

◆ init()

◆ remove()

template<typename T >
void Aleph::Powerful_Array_Policy< T >::remove ( const Array< T > &  data,
size_t  idx 
)
inline

Member Data Documentation

◆ cnt

◆ sum


The documentation for this struct was generated from the following file: