#include using namespace std; using lint = long long; using pint = pair; using plint = pair; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define ALL(x) (x).begin(), (x).end() #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template void ndarray(vector& vec, const V& val, int len) { vec.assign(len, val); } template void ndarray(vector& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); } template bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } template bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); } template pair operator+(const pair &l, const pair &r) { return make_pair(l.first + r.first, l.second + r.second); } template pair operator-(const pair &l, const pair &r) { return make_pair(l.first - r.first, l.second - r.second); } template vector sort_unique(vector vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template istream &operator>>(istream &is, vector &vec) { for (auto &v : vec) is >> v; return is; } template ostream &operator<<(ostream &os, const vector &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; } #if __cplusplus >= 201703L template istream &operator>>(istream &is, tuple &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; } template ostream &operator<<(ostream &os, const tuple &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; } #endif template ostream &operator<<(ostream &os, const deque &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; } template ostream &operator<<(ostream &os, const set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_set &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_multiset &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const pair &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; } template ostream &operator<<(ostream &os, const map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } template ostream &operator<<(ostream &os, const unordered_map &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } #ifdef HITONANODE_LOCAL #define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl #else #define dbg(x) {} #endif // Convolution by FFT (Fast Fourier Transform) // Algorithm based on // Verified: ATC001C (168 ms) using cmplx = std::complex; void fft(int N, std::vector &a, double dir) { int i = 0; for (int j = 1; j < N - 1; j++) { for (int k = N >> 1; k > (i ^= k); k >>= 1) ; if (j < i) std::swap(a[i], a[j]); } std::vector zeta_pow(N); for (int i = 0; i < N; i++) { double theta = M_PI / N * i * dir; zeta_pow[i] = {cos(theta), sin(theta)}; } for (int m = 1; m < N; m *= 2) { for (int y = 0; y < m; y++) { cmplx fac = zeta_pow[N / m * y]; for (int x = 0; x < N; x += 2 * m) { int u = x + y; int v = x + y + m; cmplx s = a[u] + fac * a[v]; cmplx t = a[u] - fac * a[v]; a[u] = s; a[v] = t; } } } } template std::vector conv_cmplx(const std::vector &a, const std::vector &b) { int N = 1; while (N < (int)a.size() + (int)b.size()) N *= 2; std::vector a_(N), b_(N); for (int i = 0; i < (int)a.size(); i++) a_[i] = a[i]; for (int i = 0; i < (int)b.size(); i++) b_[i] = b[i]; fft(N, a_, 1); fft(N, b_, 1); for (int i = 0; i < N; i++) a_[i] *= b_[i]; fft(N, a_, -1); for (int i = 0; i < N; i++) a_[i] /= N; return a_; } // retval[i] = \sum_j a[j]b[i - j] // Requirement: length * max(a) * max(b) < 10^15 template std::vector fftconv(const std::vector &a, const std::vector &b) { std::vector ans = conv_cmplx(a, b); std::vector ret(ans.size()); for (int i = 0; i < (int)ans.size(); i++) ret[i] = floor(ans[i].real() + 0.5); ret.resize(a.size() + b.size() - 1); return ret; } int main() { int N, Q; cin >> N >> Q; vector A(N), R(Q); cin >> A >> R; vector c(N); for (auto i : R) { c[(N - i) % N]++; } auto cv = fftconv(A, c); FOR(i, N, cv.size()) cv[i % N] += cv[i]; REP(i, N) cout << cv[i] << ' '; cout << '\n'; }