8000 solved 0x13 1920 · jo0n-lab/basic-algo-lecture@0381da4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0381da4

Browse files
author
cuberry
committed
solved 0x13 1920
1 parent 8a6f125 commit 0381da4

File tree

9 files changed

+44
-0
lines changed

9 files changed

+44
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0x13/v1920/main

24 KB
Binary file not shown.

0x13/v1920/main.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int N, M;
5+
int arr[100002];
6+
int target[100002];
7+
8+
int main() {
9+
ios::sync_with_stdio(false);
10+
cin.tie(NULL);
11+
12+
cin >> N;
13+
for (int i = 1; i <= N; i++)
14+
cin >> arr[i];
15+
cin >> M;
16+
for (int i = 1; i <= M; i++)
17+
cin >> target[i];
18+
19+
sort(arr + 1, arr + N + 1);
20+
21+
for (int i = 1; i <= M; i++) {
22+
int t = target[i];
23+
int st = 1;
24+
int en = N;
25+
26+
int mid = (st + en) / 2;
27+
int ans = 0;
28+
while (st <= en) {
29+
if (t == arr[mid]) {
30+
ans = 1;
31+
break;
32+
} else if (t < arr[mid])
33+
en = mid - 1;
34+
else
35+
st = mid + 1;
36+
mid = (st + en) / 2;
37+
}
38+
cout << ans << "\n";
39+
}
40+
}

0x13/v1920/tc1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
5
2+
4 1 5 2 3
3+
5
4+
1 3 7 9 5

0 commit comments

Comments
 (0)
0