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;

const int N = (1<<20)+5;

int n, t, a[N];

void compute(int* a, int n) {
    if (n == 1) return;
    int m = n / 2;
    for (int i = 0; i < m; ++i) {
        swap(a[i], a[i + m]);
    }
    compute(a, m);
    compute(a + m, m);
}

void solve() {
    cin >> n >> t;
    int m = (1 << n);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    if (t & 1) compute(a, m);
    for (int i = 0; i < m; ++i) {
        cout << a[i] << ' ';
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);

    int z = 1;
    while (z--) solve();
    return 0;
}