Kyopro Library
 
読み取り中…
検索中…
一致する文字列を見つけられません
zeta_mobius.hpp
[詳解]
1#include"../../kyopro_library/template.hpp"
2
3/// @brief ゼータ変換・メビウス変換
4namespace ZetaMobius {
5 /// @brief 高速ゼータ変換(下位集合)
6 /// @brief v'[s] = Σ_{t⊆s} v[t] なる v' を返す
7 /// @note |v| = 2^N として O(N 2^N)
8 template<typename Monoid>
9 vector<typename Monoid::Type> SubsetZeta(vector<typename Monoid::Type> v) {
10 int n=__lg(v.size());
11 for(int i=0; i<n; i++) for(int j=0; j<1<<n; j++) {
12 if(j>>i&1) v[j]=Monoid::op(v[j],v[j^(1<<i)]);
13 }
14 return v;
15 }
16
17 /// @brief 高速ゼータ変換(上位集合)
18 /// @brief v'[s] = Σ_{t⊇s} v[t] なる v' を返す
19 /// @note |v| = 2^N として O(N 2^N)
20 template<typename Monoid>
21 vector<typename Monoid::Type> SupersetZeta(vector<typename Monoid::Type> v) {
22 int n=__lg(v.size());
23 for(int i=0; i<n; i++) for(int j=0; j<1<<n; j++) {
24 if(~j>>i&1) v[j]=Monoid::op(v[j],v[j^(1<<i)]);
25 }
26 return v;
27 }
28
29 /// @brief 高速メビウス変換(下位集合)
30 /// @brief v[s] = Σ_{t⊆s} v'[t] なる v' を返す
31 /// @note 逆変換が必要なので、v は可換群の元である必要がある
32 /// @note |v| = 2^N として O(N 2^N)
33 template<typename Abel>
34 vector<typename Abel::Type> SubsetMobius(vector<typename Abel::Type> v) {
35 int n=__lg(v.size());
36 for(int i=0; i<n; i++) for(int j=0; j<1<<n; j++) {
37 if(j>>i&1) v[j]=Abel::op(v[j],Abel::inv(v[j^(1<<i)]));
38 }
39 return v;
40 }
41
42 /// @brief 高速メビウス変換(上位集合)
43 /// @brief v[s] = Σ_{t⊇s} v'[t] なる v' を返す
44 /// @note 逆変換が必要なので、v は可換群の元である必要がある
45 /// @note |v| = 2^N として O(N 2^N)
46 template<typename Abel>
47 vector<typename Abel::Type> SupersetMobius(vector<typename Abel::Type> v) {
48 int n=__lg(v.size());
49 for(int i=0; i<n; i++) for(int j=0; j<1<<n; j++) {
50 if(~j>>i&1) v[j]=Abel::op(v[j],Abel::inv(v[j^(1<<i)]));
51 }
52 return v;
53 }
54}
55
56#include"../../kyopro_library/others/monoid.hpp"
57#include"../../kyopro_library/others/abel.hpp"
ゼータ変換・メビウス変換
vector< typename Abel::Type > SupersetMobius(vector< typename Abel::Type > v)
高速メビウス変換(上位集合)
vector< typename Monoid::Type > SupersetZeta(vector< typename Monoid::Type > v)
高速ゼータ変換(上位集合)
vector< typename Monoid::Type > SubsetZeta(vector< typename Monoid::Type > v)
高速ゼータ変換(下位集合)
vector< typename Abel::Type > SubsetMobius(vector< typename Abel::Type > v)
高速メビウス変換(下位集合)