1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cstdio>

const int MAX_N = (1<<20)+9;
int a[MAX_N];

int main() {
    int n, t;
    scanf("%d%d", &n, &t);
    n = 1<<n;
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    if (t&1) {
        printf("%d", a[n-1]);
        for (int i = n-2; i >= 0; --i)
            printf(" %d", a[i]);
    } else {
        printf("%d", a[0]);
        for (int i = 1; i < n; ++i)
            printf(" %d", a[i]);
    }
    printf("\n");
}