#include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> using namespace std; #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define REP(i,n) for(int i = 0; i < (n); ++i) #define REPD(i, a, b) for(int i = (a); i > (b); i--) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define LL long long #define ULL unsigned long long #define PII pair<int,int> #define VI vector<int> #define VLL vector<long long> #define VULL vector<unsigned long long> #define VPII vector<pair<int,int> > #define PLL pair<long long,long long> #define VPLL vector<pair<long long,long long> > #define F first #define S second #define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++) #define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define present(container, element) (container.find(element) != container.end()) #define ft(a) __typeof((a).begin()) #define ld long double #define fi first #define se second #define mk make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define bitcount(n) __builtin_popcountll(n) #define pii pair<int, int> typedef complex<ld> cplex; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ii, int> iii; #define SORT(v) sort((v).begin(),(v).end()) #define UN(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end()) const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; const double EPS = 1e-12; const double PI = acos(-1); class TasProblem { int n; int t; vector<int> vec; public: void virtual Solve() { cin >> n; cin >> t; int amount = pow(2, n); int d; for (int i = 0; i < amount; i++) { cin >> d; vec.push_back(d); } if (t % 2 == 0) { for (int i = 0; i < amount; i++) { cout << vec[i] << " "; } } else { for (int i = amount - 1; i >= 0; i--) { cout << vec[i] << " "; } } } }; int main() { TasProblem *p = new TasProblem(); p->Solve(); delete p; 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | #include <cassert> #include <iostream> #include <istream> #include <fstream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory> #include <ctime> #include <bitset> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <bitset> using namespace std; #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define REP(i,n) for(int i = 0; i < (n); ++i) #define REPD(i, a, b) for(int i = (a); i > (b); i--) #define RI(X) scanf("%d", &(X)) #define RII(X, Y) scanf("%d%d", &(X), &(Y)) #define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z)) #define DRI(X) int (X); scanf("%d", &X) #define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y) #define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z) #define RS(X) scanf("%s", (X)) #define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0) #define MP make_pair #define PB push_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define LL long long #define ULL unsigned long long #define PII pair<int,int> #define VI vector<int> #define VLL vector<long long> #define VULL vector<unsigned long long> #define VPII vector<pair<int,int> > #define PLL pair<long long,long long> #define VPLL vector<pair<long long,long long> > #define F first #define S second #define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++) #define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define present(container, element) (container.find(element) != container.end()) #define ft(a) __typeof((a).begin()) #define ld long double #define fi first #define se second #define mk make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define bitcount(n) __builtin_popcountll(n) #define pii pair<int, int> typedef complex<ld> cplex; typedef vector<int> vi; typedef pair<int, int> ii; typedef pair<ii, int> iii; #define SORT(v) sort((v).begin(),(v).end()) #define UN(v) SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end()) const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; const double EPS = 1e-12; const double PI = acos(-1); class TasProblem { int n; int t; vector<int> vec; public: void virtual Solve() { cin >> n; cin >> t; int amount = pow(2, n); int d; for (int i = 0; i < amount; i++) { cin >> d; vec.push_back(d); } if (t % 2 == 0) { for (int i = 0; i < amount; i++) { cout << vec[i] << " "; } } else { for (int i = amount - 1; i >= 0; i--) { cout << vec[i] << " "; } } } }; int main() { TasProblem *p = new TasProblem(); p->Solve(); delete p; return 0; } |