-
Notifications
You must be signed in to change notification settings - Fork 0
/
a58_m3_hanamard.cpp
37 lines (30 loc) · 806 Bytes
/
a58_m3_hanamard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
vector <long long> solve(int l, int r) {
if (l == r) return {v[l]};
int m = (l + r) / 2;
vector <long long> res[4];
res[0] = solve(l, m);
res[1] = solve(m + 1, r);
for (int i = 0; i < m - l + 1; i++) {
res[2].push_back(res[0][i]);
res[3].push_back(-res[1][i]);
}
for (int i = 0; i < m - l + 1; i++) {
res[0][i] += res[1][i];
res[2][i] += res[3][i];
}
res[0].insert(res[0].end(), res[2].begin(), res[2].end());
return res[0];
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
v.resize(n);
for (auto &x : v) cin >> x;
vector <long long> ans(solve(0, n - 1));
for (auto x : ans) cout << x << ' ';
return 0;
}