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
38
39
40
41
42
43
44
45
46
47
48
#include<cstdio>
#include<vector>

int pos = 0;
int reversed[1048576];

int pow(int x) {
    if (x == 1) return 2;
    int xx = pow(x / 2);
    xx = xx * xx;
    return x % 2 == 0 ? xx : xx * x;
}

void generate_reversed(int* start, int* end) {
    if (start + 1 == end) {
        reversed[pos++] = *end;
        reversed[pos++] = *start;
    } else {
        int* middle = start + ((end - start + 1) / 2) - 1;
        generate_reversed(middle + 1, end);
        generate_reversed(start, middle);
    }
}

int main() {
    int numbers[1048576];
    int n, t;
    scanf("%d %d", &n, &t);
    int len = pow(n);
    for (int i = 0; i < len; ++i) {
        scanf("%d", &numbers[i]);
    }

    if (t % 2 == 1) {
        generate_reversed(&numbers[0], &numbers[len - 1]);
        printf("%d", reversed[0]);
        for (int i = 1; i < len; ++i) {
            printf(" %d", reversed[i]);
        }
        printf("\n");
    } else {
        printf("%d", numbers[0]);
        for (int i = 1; i < len; ++i) {
            printf(" %d", numbers[i]);
        }
        printf("\n");
    }
}