-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16566.cpp
43 lines (38 loc) · 931 Bytes
/
16566.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e6 * 4 + 1;
int parent[MAX];
int find(int x) {
if (parent[x] == x) return x;
return parent[x] = find(parent[x]);
}
void merge(int x, int y) {
int px = find(x);
int py = find(y);
if (px != py) {
parent[px] = py;
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
vector<int> arr;
for (int i = 0; i < M; i++) {
int t; cin >> t;
arr.push_back(t);
}
sort(arr.begin(), arr.end());
for (int i = 0; i < N; i++) parent[i] = i;
for (int i = 0; i < K; i++) {
int t; cin >> t;
auto it = upper_bound(arr.begin(), arr.end(), t);
int idx = find(parent[it - arr.begin()]);
cout << arr[idx] << '\n';
merge(idx, idx + 1);
}
return 0;
}