-
Notifications
You must be signed in to change notification settings - Fork 12
/
1049.cpp
79 lines (75 loc) · 1.45 KB
/
1049.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <climits>
#include <cmath>
#include <set>
using namespace std;
int num[100005];
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int f(int x,int n)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(num[mid]<x)
{
low=mid+1;
}
else if(num[mid]>x)
{
high=mid-1;
}
else
break;
}
while(mid-1>=0)
{
if(num[mid-1]==x)
mid--;
else
break;
}
if(num[mid]==x)
return mid;
else
return -1;
}
int main()
{
//freopen("in.txt","r",stdin);
int n,m,t,con;
while(scanf("%d %d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
qsort(num,n,sizeof(num[0]),cmp);
for(int i=0;i<m;i++)
{
scanf("%d",&t);
int index=f(t,n);
//printf("index--> %d \n",index);
if(index==-1)
printf("0\n");
else
{
con=0;
while(num[index]==t)
{
con++;
index++;
if(index==n)
break;
}
printf("%d\n",con);
}
}
}
return 0;
}//Parsed in 0.138 seconds