#include <bits/stdc++.h> #ifndef getchar_unlocked #define getchar_unlocked getchar #endif // getchar_unlocked inline int readint() { char zn; bool m = false; while (1) { zn = getchar_unlocked(); if(zn == '-') m = true; if (zn >= '0' && zn <= '9') break; } int x = 0; while (1) { x = (x << 1) + (x << 3) + zn - '0'; zn = getchar_unlocked(); if (zn < '0' || zn > '9') return m? -x : x; } } using namespace std; int main() { int n = readint(); n = 1<<n; int* tab = new int[n]; int t = readint(); for(int i = 0; i < n; i++) { tab[i] = readint(); } if(t % 2) { for(int i = n-1; i >= 0; i--) { printf("%d ", tab[i]); } }else { for(int i = 0; i < n; i++) { printf("%d ", tab[i]); } } }
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 | #include <bits/stdc++.h> #ifndef getchar_unlocked #define getchar_unlocked getchar #endif // getchar_unlocked inline int readint() { char zn; bool m = false; while (1) { zn = getchar_unlocked(); if(zn == '-') m = true; if (zn >= '0' && zn <= '9') break; } int x = 0; while (1) { x = (x << 1) + (x << 3) + zn - '0'; zn = getchar_unlocked(); if (zn < '0' || zn > '9') return m? -x : x; } } using namespace std; int main() { int n = readint(); n = 1<<n; int* tab = new int[n]; int t = readint(); for(int i = 0; i < n; i++) { tab[i] = readint(); } if(t % 2) { for(int i = n-1; i >= 0; i--) { printf("%d ", tab[i]); } }else { for(int i = 0; i < n; i++) { printf("%d ", tab[i]); } } } |