-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path1.cpp
More file actions
60 lines (59 loc) · 1022 Bytes
/
Copy path1.cpp
File metadata and controls
60 lines (59 loc) · 1022 Bytes
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
//Find the Union and Intersection of the two sorted arrays.
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int arr1[n];
int arr2[m];
REP(i, 0, n) {
cin >> arr1[i];
}
REP(i, 0, m) {
cin >> arr2[i];
}
set<int> s;
REP(i, 0, n) {
s.insert(arr1[i]);
}
REP(i, 0, m) {
s.insert(arr2[i]);
}
set<int>::iterator itr;
for (itr = s.begin(); itr != s.end(); itr++)
{
cout << *itr << " ";
}
cout << endl;
int ins[min(m, n)];
int i = 0, j = 0, k = 0;
while (i < n && j < m) {
if (arr1[i] == arr2[j]) {
ins[k] = arr1[i];
i++;
j++;
k++;
} else if (arr1[i] > arr2[j]) {
i++;
j++;
} else {
i++;
j++;
}
}
for (int i = 0; i < k; i++) {
cout << ins[i] << " ";
}
}