-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_search.cpp
64 lines (64 loc) · 1.34 KB
/
binary_search.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#includeiostream
#includealgorithm
#includecstdio
#includecstring
#includecmath
#includecctype
#includeiomanip
#includemap
#includevector
#includelist
#includedeque
#includestack
#includequeue
#includeset
#includecctype
#includestring
#includestdexcept
#includefstream
#includesstream
#includesstream
#define mem(a,b) memset(a,b,sizeof(a))
#define debug() puts(what the fuck!)
#define dedebug() puts(what the fuck!!!)
#define ll long long
#define ull unsigned long long
#define speed {iossync_with_stdio(false); cin.tie(0); cout.tie(0); };
using namespace std;
const double PI = acos(-1.0);
const int maxn = 1e6 + 10;
const int N = 2e2 + 10;
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double esp_0 = 1e-6;
const double gold = (1 + sqrt(5)) 2;
templatetypename T
inline void rd(T&x) {
int temp = 1;
char c = getchar();
x = 0;
while (c '9' c '0') {if (c == '-')temp = -1; c = getchar();}
while (c = '0' && c = '9') {x = x 10 + c - '0';c = getchar();}
x = temp;
}
ll gcd(ll x, ll y) {return y gcd(y, x % y) x;}
int a[maxn];
int vis[maxn];
int n;
signed main() {
cin n;
mem(vis, 0);
for (int i = 1; i = n; ++i) {
cin a[i];
vis[a[i]] = i;
}
sort(a + 1, a + 1 + n);
int q;
while (cin q) {
int pos = lower_bound(a + 1, a + 1 + n, q) - a;
if (a[pos] ==q)cout vis[a[pos]] endl;
else cout 0 endl;
}
return 0;
}