|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Policy: "powerful array" sum = sum(cnt[x]^2 * x). More...
#include <tpl_mo_algorithm.H>
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 long > | cnt |
| long long | sum = 0 |
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
| T | Element type (must be hashable and arithmetic-like). |
Definition at line 452 of file tpl_mo_algorithm.H.
Definition at line 454 of file tpl_mo_algorithm.H.
Definition at line 466 of file tpl_mo_algorithm.H.
References Aleph::Powerful_Array_Policy< T >::cnt, and Aleph::Powerful_Array_Policy< T >::sum.
|
inline |
Definition at line 480 of file tpl_mo_algorithm.H.
References Aleph::Powerful_Array_Policy< T >::sum.
Definition at line 459 of file tpl_mo_algorithm.H.
References Aleph::Powerful_Array_Policy< T >::cnt, Aleph::divide_and_conquer_partition_dp(), and Aleph::Powerful_Array_Policy< T >::sum.
Definition at line 473 of file tpl_mo_algorithm.H.
References Aleph::Powerful_Array_Policy< T >::cnt, and Aleph::Powerful_Array_Policy< T >::sum.
Definition at line 456 of file tpl_mo_algorithm.H.
Referenced by Aleph::Powerful_Array_Policy< T >::add(), Aleph::Powerful_Array_Policy< T >::init(), and Aleph::Powerful_Array_Policy< T >::remove().
Definition at line 457 of file tpl_mo_algorithm.H.
Referenced by Aleph::Powerful_Array_Policy< T >::add(), Aleph::Powerful_Array_Policy< T >::answer(), Aleph::Powerful_Array_Policy< T >::init(), and Aleph::Powerful_Array_Policy< T >::remove().