File tree Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Expand file tree Collapse file tree 3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change 1+ #pragma once
2+ #include < algorithm>
3+ #include < utility>
4+ #include < vector>
5+
6+ template <class Int > struct f2_vector_space {
7+ std::vector<Int> basis;
8+
9+ f2_vector_space () = default ;
10+
11+ Int add (Int x) {
12+ for (const Int &b : basis) x = std::min (x, x ^ b);
13+
14+ if (x) {
15+ basis.push_back (x);
16+ return x;
17+ } else {
18+ return Int (0 );
19+ }
20+ }
21+ };
22+
23+ std::vector<int > f2_intersection (const std::vector<int > &A, const std::vector<int > &B) {
24+ f2_vector_space<long long > tmp;
25+ for (int a : A) tmp.add (((long long )a << 32 ) + a);
26+
27+ std::vector<int > ret;
28+
29+ for (int b : B) {
30+ long long v = (long long )b << 32 ;
31+
32+ auto u = tmp.add (v);
33+ if (u < (1LL << 32 )) ret.push_back (u);
34+ }
35+
36+ return ret;
37+ }
Original file line number Diff line number Diff line change 1+ ---
2+ title : $\mathbb{F}_{2}$ linear space ($\mathbb{F}_{2}$ 線形空間)
3+ documentation_of : ./f2_linear_space.hpp
4+ ---
5+
6+ $\mathbb{F}_ {2}$ 線形空間に関する各種演算.
7+
8+ ## 使用方法
9+
10+ ` A ` の元で張られる線形空間と ` B ` の元で張られる線形空間の共通部分の基底を一つ求める関数方法.
11+
12+ ``` cpp
13+ int n, m;
14+ vector<int > A (n), B(m);
15+
16+ vector<int > C = f2_intersection(A, B);
17+ ```
18+
19+ ## 問題例
20+
21+ - [Library Checker: Intersection of F_2 vector spaces](https://judge.yosupo.jp/problem/intersection_of_f2_vector_spaces)
Original file line number Diff line number Diff line change 1+ #define PROBLEM " https://judge.yosupo.jp/problem/intersection_of_f2_vector_spaces"
2+ #include " ../f2_vector_space.hpp"
3+
4+ #include < iostream>
5+ using namespace std ;
6+
7+ int main () {
8+ cin.tie (nullptr );
9+ ios::sync_with_stdio (false );
10+
11+ int T;
12+ cin >> T;
13+
14+ while (T--) {
15+ int n;
16+ cin >> n;
17+ vector<int > A (n);
18+ for (int &x : A) cin >> x;
19+
20+ int m;
21+ cin >> m;
22+ vector<int > B (m);
23+ for (int &x : B) cin >> x;
24+
25+ auto C = f2_intersection (A, B);
26+
27+ cout << C.size ();
28+ for (int x : C) cout << ' ' << x;
29+ cout << ' \n ' ;
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments