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
49
50
51
52
53
#include <cstdio>
#include <iostream>

typedef unsigned long long ull;
typedef unsigned int uint;
using namespace std;

void tas(int *begin, int *end)
{
    if(end - begin <2)
        return;
    if(end - begin == 2)
    {
        std::swap(*begin, *(begin+1));
        return;
    }
    else
    {
        int distance = end - begin;
        int *mid = begin + distance/2;
        tas(begin, mid);
        tas(mid, end);
        for(int i = 0; i < distance/2 ; i++)
            std::swap(*(begin + i), *(mid + i));
    }
}

int main()
{
    int n;
    int tasowania;
    std::cin >> n >> tasowania;
    int count = 1;
    count <<= n;
    int * tab = new int[count];
    for(int i = 0; i < count; i++)
        std::cin >> tab[i];
//    tas(tab, tab+count);
//    tas(tab, tab+count);
    if(tasowania % 2 == 0)
    {
        for(int i = 0; i < count; i++)
            std::cout << tab[i] << " ";
    }
    else
    {
        for(int i = 0; i < count; i++)
            std::cout << tab[count - 1 - i] << " ";
    }
    std::cout << "\n";

    return 0;
}