-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB-RoofConstruction.cpp
126 lines (106 loc) · 2.73 KB
/
B-RoofConstruction.cpp
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 "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
int mini = INT_MAX;
vector<int> minAns;
bool cost(vector<int> vector1) {
int ans = 0;
for (int i = 0; i < vector1.size() - 1; ++i) {
ans = max(ans, (vector1[i] ^ vector1[i + 1]));
if (ans>mini) break;
}
if(ans < mini) {
mini = ans;
return true;
}
return false;
}
void permutation(vector<int> seq, vector<int> answer) {
if (seq.size() == 0) {
if(cost(answer)) {
minAns = answer;
}
return;
}
for (int i = 0; i < seq.size(); ++i) {
int ch = seq[i];
vector<int> rest;
for (auto ele: seq) if (ele != ch) rest.emplace_back(ele);
answer.emplace_back(ch);
permutation(rest, answer);
answer.pop_back();
}
}
void solve() {
/*int n;
cin>>n;
vector<int> s;
for (int i = 0; i < n; ++i)
{
s.emplace_back(i);
}
mini = INT_MAX;
vector<int> ans;
permutation(s, ans);
for (auto ele: minAns) cout << ele << " ";
cout << endl;*/
ll n;
cin >> n;
ll k=1LL;
n--;
while(2*k<=n) k=k*2;
for(ll i=n;i>=k;i--) cout<<i<<" ";
for(ll i=0;i<k;i++) cout<<i<<" ";
cout<<endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}