#ifdef ONLINE_JUDGE #pragma GCC optimize("O3,unroll-loops") #pragma GCC…
- User
#ifdef ONLINE_JUDGE #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,avx2,tune=native") #endif #include <bits/stdc++.h>
using namespace std; using ll = long long; //using ld = long double;
constexpr int ITERS = 100; constexpr double one = 1; constexpr double hundred = 100;
vector<vector> pow(vector<vector> m1, vector<vector> m2) { vector<vector> m3(3, vector(3)); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 3; ++k) { m3[i][j] += m1[i][k] * m2[k][j]; } } } for (int i = 0; i < 3; ++i) { double sum = m3[i][0] + m3[i][1] + m3[i][2]; for (int j = 0; j < 3; ++j) { m3[i][j] = m3[i][j] / sum; } } return m3; }
vector<vector> binpow(vector<vector> m) { for (int i = 0; i < ITERS; ++i) m = pow(m, m); return m; }
vector vecMul(vector<vector> m, vector p) { return { p[0] * m[0][0] + p[1] * m[1][0] + p[2] * m[2][0], p[0] * m[0][1] + p[1] * m[1][1] + p[2] * m[2][1], p[0] * m[0][2] + p[1] * m[1][2] + p[2] * m[2][2] }; }
//FFT //using comp = complex; //const double PI = acos(-1); // //constexpr double PI2 = 6.283185307179586; // //void fft(vector& a, vector& res, int n, comp x, int abg, int astep, int rbg) { // if (n == 1) { // res[rbg] = a[abg]; // return; // } // fft(a, res, n / 2, x * x, abg, astep * 2, rbg); // fft(a, res, n / 2, x * x, abg + astep, astep * 2, rbg + n / 2); // comp w = 1; // for (int i = 0; i < n/2; ++i) { // comp rc = res[rbg + i]; // comp rd = res[rbg + i + n / 2]; // res[rbg + i] = rc + w * rd; // res[rbg + i + n / 2] = rc - w * rd; // w *= x; // } //} // //int log2(int x) { // int res = 31 - __builtin_clz(x); // if (1 << res < x) res++; // return res; //} // //vector mult(vector& aReference, vector& bReference) { // int n = 1 << log2(int(aReference.size() + bReference.size())); // vector ra(n), rb(n), a(aReference.begin(), aReference.end()), b(bReference.begin(), bReference.end()); // a.resize(n, 0), b.resize(n, 0); // comp x = comp(cos(2 * PI / n), sin(2 * PI / n)); // fft(a, ra, n, x, 0, 1, 0); // fft(b, rb, n, x, 0, 1, 0); // vector rab(n); // for (int i = 0; i < n; ++i) rab[i] = ra[i] * rb[i] / comp(n); // x = comp(cos(2 * PI / n), -sin(2 * PI / n)); // vector c(n); // fft(rab, c, n, x, 0, 1, 0); // vector cc(n); // for (int i = 0; i < n; i++) cc[i] = c[i].real(); // return cc; //}
using comp = complex; const double PI = acos(-1);
int log2(int x) { int res = 31 - __builtin_clz(x); if (1 << res < x) res++; return res; }
constexpr double PI2 = 6.283185307179586; const int LG = 18; const int R = 1 << LG;
comp pa[R], pb[R]; vector rev[LG+1]; double result[R]; vector pw[LG+1], pwi[LG+1];
inline void fft(comp a[], int r, int lg) { for (int i = 0; i < r; ++i) { if (i < rev[lg][i]) { swap(a[i], a[rev[lg][i]]); } } for (int lgi = 1; lgi <= lg; lgi++) { int l = 1 << lgi; for (int i = 0; i < r; i += l) { comp t; comp *p1 = a + i, *p2 = a + i + (l >> 1); comp *pe = a + i + (l >> 1); auto ppw = pw[lgi].begin(); while (p1 != pe) { t = *p2 * *ppw; *p2 = *p1 - t; *p1 += t; ++p1; ++p2; ++ppw; } } } }
- Assistant
The provided C++ code contains a complex and nuanced program aimed at solving a computational problem involving probabilities and FFT-based polynomial multiplications. The provided code has some warnings and errors that need to be addressed.
Let's break down the errors and warnings and how you might adjust the code:
-
These warnings occur because you are comparing signed integers () with unsigned types such as , which is the return type of . Fix these by declaring loop counters as instead of .
-