Skip to content

Commit 553af98

Browse files
Add files via upload
1 parent e96001d commit 553af98

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main() {
7+
int tc;
8+
cin >> tc;
9+
while (tc--) {
10+
int n, x;
11+
cin >> n >> x;
12+
13+
vector<int> ans;
14+
int i = 0;
15+
int orSoFar = 0;
16+
for (; i < n - 1; i++) {
17+
if ((i & x) == i) {
18+
orSoFar |= i;
19+
ans.push_back(i);
20+
} else {
21+
break;
22+
}
23+
}
24+
25+
if (i == n - 1 && (i | orSoFar) == x) {
26+
ans.push_back(i);
27+
} else {
28+
for (; i < n; i++) {
29+
ans.push_back(x);
30+
}
31+
}
32+
33+
for (int i = 0; i < n; i++) {
34+
cout << ans[i] << " ";
35+
}
36+
cout << endl;
37+
}
38+
39+
return 0;
40+
}

0 commit comments

Comments
 (0)