-
Notifications
You must be signed in to change notification settings - Fork 1
/
01269.c
61 lines (51 loc) · 1 KB
/
01269.c
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
#include <stdio.h>
void swap(int* a, int* b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
int partition(int arr[], int l, int r) {
int pivot = arr[r];
int i = l-1;
for (int j = l; j <= r-1; j++) {
if (arr[j] <= pivot) {
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i+1], &arr[r]);
return i + 1;
}
void quickSort(int arr[], int l, int r) {
if (l < r) {
int pivot = partition(arr, l, r);
quickSort(arr, l, pivot-1);
quickSort(arr, pivot+1, r);
}
}
int binarySearch(int arr[], int l, int r, int n) {
while (l <= r) {
int m = l+(r-l)/2;
if (arr[m] == n) return 1;
if (arr[m] < n) l = m+1;
else r = m - 1;
}
return 0;
}
int main(void) {
int a, b, count = 0;
int arr[200000], n;
scanf("%d %d", &a, &b);
for (int i=0; i<a; i++) {
scanf("%d", &arr[i]);
}
quickSort(arr, 0, a-1);
for (int i=0; i<b; i++) {
scanf("%d", &n);
if (binarySearch(arr, 0, a-1, n) != 0) {
count++;
}
}
printf("%d", a+b-count*2);
return 0;
}