# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
639822 | | ggoh | 씽크스몰 (kriii3_TT) | C++14 | | 1510 ms | 179540 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lint long long
using namespace std;
//source : https://github.com/koosaga/DeobureoMinkyuParty/blob/master/teamnote.pdf
//no ntt
typedef complex<double> base;
void fft(vector<base> &a, bool inv)
{
int n = a.size(), j = 0;
vector<base> roots(n / 2);
for (int i = 1; i < n; i++)
{
int bit = (n >> 1);
while (j >= bit)
{
j -= bit;
bit >>= 1;
}
j += bit;
if (i < j)
swap(a[i], a[j]);
}
double ang = 2 * acos(-1) / n * (inv ? -1 : 1);
for (int i = 0; i < n / 2; i++)
{
roots[i] = base(cos(ang * i), sin(ang * i));
}
for (int i = 2; i <= n; i <<= 1)
{
int step = n / i;
for (int j = 0; j < n; j += i)
{
for (int k = 0; k < i / 2; k++)
{
base u = a[j + k], v = a[j + k + i / 2] * roots[step * k];
a[j + k] = u + v;
a[j + k + i / 2] = u - v;
}
}
}
if (inv)
for (int i = 0; i < n; i++)
a[i] /= n;
}
vector<lint> multiply(vector<lint> &v, vector<lint> &w)
{
int n = 2;
while (n < v.size() + w.size())
n <<= 1;
vector<base> v1(n), v2(n), r1(n), r2(n);
for (int i = 0; i < v.size(); i++)
{
v1[i] = base(v[i] >> 15, v[i] & 32767);
}
for (int i = 0; i < w.size(); i++)
{
v2[i] = base(w[i] >> 15, w[i] & 32767);
}
fft(v1, 0);
fft(v2, 0);
for (int i = 0; i < n; i++)
{
int j = (i ? (n - i) : i);
base ans1 = (v1[i] + conj(v1[j])) * base(0.5, 0);
base ans2 = (v1[i] - conj(v1[j])) * base(0, -0.5);
base ans3 = (v2[i] + conj(v2[j])) * base(0.5, 0);
base ans4 = (v2[i] - conj(v2[j])) * base(0, -0.5);
r1[i] = (ans1 * ans3) + (ans1 * ans4) * base(0, 1);
r2[i] = (ans2 * ans3) + (ans2 * ans4) * base(0, 1);
}
fft(r1, 1);
fft(r2, 1);
vector<lint> ret(n);
for (int i = 0; i < n; i++)
{
lint av = (lint)round(r1[i].real());
lint bv = (lint)round(r1[i].imag()) + (lint)round(r2[i].real());
lint cv = (lint)round(r2[i].imag());
ret[i] = (av << 30) + (bv << 15) + cv;
}
return ret;
}
int N, M, x;
vector<lint> f, g;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>N>>M;
for (int i = 0; i <= N; i++)
{
cin>>x;
f.push_back(x);
}
for (int i = 0; i <= M; i++)
{
cin>>x;
g.push_back(x);
}
vector<lint> r = multiply(f, g);
lint xo = 0;
for (int i = 0; i < r.size(); i++)
xo ^= r[i];
cout<<xo;
}
Compilation message (stderr)
tt.cpp: In function 'std::vector<long long int> multiply(std::vector<long long int>&, std::vector<long long int>&)':
tt.cpp:49:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | while (n < v.size() + w.size())
| ~~^~~~~~~~~~~~~~~~~~~~~
tt.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
tt.cpp:56:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < w.size(); i++)
| ~~^~~~~~~~~~
tt.cpp: In function 'int main()':
tt.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for (int i = 0; i < r.size(); i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |