#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <string> #define PB push_back #define ST first #define ND second using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using VII = vector<PII>; using LL = long long int; using ULL = unsigned long long int; const int MAXN = 1<<21; int n, t; int x[MAXN]; int main() { scanf("%d %d", &n, &t); const int pow_2_n = 1 << n; for (int i = 0 ; i < pow_2_n; ++i) { scanf("%d", &x[i]); } if (t % 2 == 0) { for (int i = 0; i < pow_2_n; ++i) { printf("%d ", x[i]); } } else { for (int i = pow_2_n - 1; i >= 0; --i) { printf("%d ", x[i]); } } return 0; }
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 54 55 | #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <iostream> #include <string> #define PB push_back #define ST first #define ND second using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using VII = vector<PII>; using LL = long long int; using ULL = unsigned long long int; const int MAXN = 1<<21; int n, t; int x[MAXN]; int main() { scanf("%d %d", &n, &t); const int pow_2_n = 1 << n; for (int i = 0 ; i < pow_2_n; ++i) { scanf("%d", &x[i]); } if (t % 2 == 0) { for (int i = 0; i < pow_2_n; ++i) { printf("%d ", x[i]); } } else { for (int i = pow_2_n - 1; i >= 0; --i) { printf("%d ", x[i]); } } return 0; } |