-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c09c07f
commit 64c16f3
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
#include <algorithm> | ||
#include <utility> | ||
#include <vector> | ||
|
||
template <class Int> struct f2_vector_space { | ||
std::vector<Int> basis; | ||
|
||
f2_vector_space() = default; | ||
|
||
Int add(Int x) { | ||
for (const Int &b : basis) x = std::min(x, x ^ b); | ||
|
||
if (x) { | ||
basis.push_back(x); | ||
return x; | ||
} else { | ||
return Int(0); | ||
} | ||
} | ||
}; | ||
|
||
std::vector<int> f2_intersection(const std::vector<int> &A, const std::vector<int> &B) { | ||
f2_vector_space<long long> tmp; | ||
for (int a : A) tmp.add(((long long)a << 32) + a); | ||
|
||
std::vector<int> ret; | ||
|
||
for (int b : B) { | ||
long long v = (long long)b << 32; | ||
|
||
auto u = tmp.add(v); | ||
if (u < (1LL << 32)) ret.push_back(u); | ||
} | ||
|
||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: $\mathbb{F}_{2}$ linear space ($\mathbb{F}_{2}$ 線形空間) | ||
documentation_of: ./f2_linear_space.hpp | ||
--- | ||
|
||
$\mathbb{F}_{2}$ 線形空間に関する各種演算. | ||
|
||
## 使用方法 | ||
|
||
`A` の元で張られる線形空間と `B` の元で張られる線形空間の共通部分の基底を一つ求める関数方法. | ||
|
||
```cpp | ||
int n, m; | ||
vector<int> A(n), B(m); | ||
|
||
vector<int> C = f2_intersection(A, B); | ||
``` | ||
## 問題例 | ||
- [Library Checker: Intersection of F_2 vector spaces](https://judge.yosupo.jp/problem/intersection_of_f2_vector_spaces) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#define PROBLEM "https://judge.yosupo.jp/problem/intersection_of_f2_vector_spaces" | ||
#include "../f2_vector_space.hpp" | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
cin.tie(nullptr); | ||
ios::sync_with_stdio(false); | ||
|
||
int T; | ||
cin >> T; | ||
|
||
while (T--) { | ||
int n; | ||
cin >> n; | ||
vector<int> A(n); | ||
for (int &x : A) cin >> x; | ||
|
||
int m; | ||
cin >> m; | ||
vector<int> B(m); | ||
for (int &x : B) cin >> x; | ||
|
||
auto C = f2_intersection(A, B); | ||
|
||
cout << C.size(); | ||
for (int x : C) cout << ' ' << x; | ||
cout << '\n'; | ||
} | ||
} |