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

int main() {
int n = 0;
int t = 0;
std::cin >> n >> t;
std::vector<int> vec;
for (int i = 0; i < 1 << n; i++) {
int temp;
std::cin >> temp; 
vec.push_back(temp);
}
if (t % 2) {
for (auto i = vec.rbegin(); i != vec.rend(); i++) 
std::cout << *i << " ";
} else {
for (auto i = vec.begin(); i != vec.end(); i++) 
std::cout << *i << " ";
}
}