mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
parent
4f8ad912fa
commit
cb93cd2db3
72
LibreOJ/108/108.cpp
Normal file
72
LibreOJ/108/108.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const double PI = std::acos(-1);
|
||||
|
||||
void FFT(std::vector<std::complex<double>>& a) {
|
||||
if (a.size() == 1) return;
|
||||
|
||||
int m = a.size() >> 1;
|
||||
std::vector<std::complex<double>> a0, a1;
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
a0.emplace_back(a[i << 1]);
|
||||
a1.emplace_back(a[i << 1 | 1]);
|
||||
}
|
||||
|
||||
FFT(a0), FFT(a1);
|
||||
|
||||
std::complex<double>
|
||||
w0{std::cos(PI / m), std::sin(PI / m)},
|
||||
w1{1.0, 0.0};
|
||||
|
||||
for (int i = 0; i < m; i++) {
|
||||
a[i] = a0[i] + w1 * a1[i];
|
||||
a[i + m] = a0[i] - w1 * a1[i];
|
||||
w1 *= w0;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, m;
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
int k = 1 << (std::__lg(n + m) + 1);
|
||||
std::vector<std::complex<double>> f(k), g(k);
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
cin >> f[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i <= m; i++) {
|
||||
cin >> g[i];
|
||||
}
|
||||
|
||||
FFT(f), FFT(g);
|
||||
|
||||
for (int i = 0; i < k; i++) {
|
||||
f[i] *= g[i];
|
||||
}
|
||||
|
||||
FFT(f);
|
||||
std::reverse(f.begin() + 1, f.end());
|
||||
|
||||
for (int i = 0; i <= n + m; i++) {
|
||||
cout << static_cast<int>(std::round(f[i].real() / k)) << ' ';
|
||||
}
|
||||
|
||||
cout << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
LibreOJ/108/data/1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/1.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/10.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/11.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/11.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/12.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/12.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/13.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/13.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/14.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/14.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/15.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/15.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/16.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/16.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/17.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/17.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/18.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/18.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/19.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/19.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/2.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/20.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/20.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/3.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/4.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/5.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/6.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/7.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/8.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/108/data/9.out
(Stored with Git LFS)
Normal file
BIN
LibreOJ/108/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user