-
Notifications
You must be signed in to change notification settings - Fork 0
/
AcWing789.cpp
49 lines (48 loc) · 966 Bytes
/
AcWing789.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
#include <iostream>
using namespace std;
int a[100005];
int main()
{
int n,q,k;
scanf("%d%d", &n, &q);
for (int i=0; i<n; i++)scanf("%d", &a[i]);
while (q-->0)
{
scanf("%d", &k);
int l = 0, r = n - 1;
while (l < r)
{
int mid = (l + r) / 2;
if (a[mid] >= k)
{
r = mid;
}
else
{
l = mid + 1;
}
}
if(a[l]!=k)
{
printf("-1 -1\n");
}
else
{
printf("%d ", l);
int l = 0, r = n - 1;
while (l < r)
{
int mid = (l + r + 1) / 2;
if (a[mid] <= k)
{
l = mid;
}
else
{
r = mid - 1;
}
}
printf("%d\n", l);
}
}
}