#include <bits/stdc++.h> #define FOR(a, b, c) for(int a=b; a<=(c); a++) using namespace std; int ciag[(1<<20)+5]; void tasuj(int p, int k){ int s=(p+k)/2; int len=(k-p)/2; if(len>0){ tasuj(p, s); tasuj(s+1, k); } FOR(i, 0, len) swap(ciag[p+i], ciag[s+i+1]); } int main(){ ios_base::sync_with_stdio(false); int pot, t; cin >> pot >> t; FOR(i, 1, (1<<pot)){ cin >> ciag[i]; } if(t%2==1) tasuj(1, (1<<pot)); FOR(i, 1, (1<<pot)) cout << ciag[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 | #include <bits/stdc++.h> #define FOR(a, b, c) for(int a=b; a<=(c); a++) using namespace std; int ciag[(1<<20)+5]; void tasuj(int p, int k){ int s=(p+k)/2; int len=(k-p)/2; if(len>0){ tasuj(p, s); tasuj(s+1, k); } FOR(i, 0, len) swap(ciag[p+i], ciag[s+i+1]); } int main(){ ios_base::sync_with_stdio(false); int pot, t; cin >> pot >> t; FOR(i, 1, (1<<pot)){ cin >> ciag[i]; } if(t%2==1) tasuj(1, (1<<pot)); FOR(i, 1, (1<<pot)) cout << ciag[i] << " "; } |