We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5ef93f7 commit 217e097Copy full SHA for 217e097
tree/20364.cpp
@@ -0,0 +1,43 @@
1
+#include <iostream>
2
+#include <algorithm>
3
+#define MAX_N 1<<21
4
+#define MAX_M 200000
5
+using namespace std;
6
+
7
+bool visit[MAX_N];
8
+int list[MAX_M];
9
+int N, M;
10
11
+void func() {
12
+ for (int i = 0; i < M; i++) {
13
+ int v = 1e9;
14
+ for (int j = list[i]; j > 0; j /= 2) {
15
+ if (visit[j]) v = min(v, j);
16
+ }
17
18
+ if (v == 1e9) {
19
+ visit[list[i]] = true;
20
+ cout << "0\n";
21
22
+ else {
23
+ cout << v << '\n';
24
25
26
+}
27
28
+void input() {
29
+ cin >> N >> M;
30
31
+ cin >> list[i];
32
33
34
35
+int main() {
36
+ cin.tie(NULL); cout.tie(NULL);
37
+ ios::sync_with_stdio(false);
38
39
+ input();
40
+ func();
41
42
+ return 0;
43
0 commit comments