/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は宝くじを購入しました。
今日は当選発表の日です。当選番号として K 個の互いに異なる正整数 A_1, A_2, \ldots, A_K が発表されました。高橋君は M 枚の宝くじを持っており、各宝くじにはそれぞれ 1 つの番号(正整数)が書かれています。高橋君の宝くじに書かれている番号を順に B_1, B_2, \ldots, B_M とすると、これらはすべて互いに異なります。
高橋君が持っている宝くじのうち、当選番号のいずれかと一致する番号が書かれているものの枚数を求めてください。
制約
- 1 \leq K \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq K)
- 1 \leq B_j \leq 10^9 (1 \leq j \leq M)
- A_1, A_2, \ldots, A_K はすべて異なる
- B_1, B_2, \ldots, B_M はすべて異なる
- 入力はすべて整数
入力
K M A_1 A_2 \ldots A_K B_1 B_2 \ldots B_M
- 1 行目には、当選番号の個数 K と、高橋君が持っている宝くじの枚数 M が、空白区切りで与えられる。
- 2 行目には、当選番号 A_1, A_2, \ldots, A_K が、空白区切りで与えられる。
- 3 行目には、高橋君が持っている宝くじの番号 B_1, B_2, \ldots, B_M が、空白区切りで与えられる。
出力
高橋君が持っている宝くじのうち、当選番号のいずれかと一致する番号が書かれているものの枚数を 1 行で出力せよ。
入力例 1
5 3 1 2 3 4 5 2 7 4
出力例 1
2
入力例 2
4 6 100 200 300 400 150 200 250 300 350 400
出力例 2
3
入力例 3
10 8 1000000000 999999999 123456789 987654321 555555555 111111111 222222222 333333333 444444444 666666666 123456789 100000000 555555555 777777777 888888888 999999999 12345 67890
出力例 3
3
Score : 266 pts
Problem Statement
Takahashi purchased lottery tickets.
Today is the day of the winning number announcement. K distinct positive integers A_1, A_2, \ldots, A_K were announced as the winning numbers. Takahashi has M lottery tickets, and each ticket has one number (a positive integer) written on it. Letting B_1, B_2, \ldots, B_M denote the numbers written on Takahashi's lottery tickets in order, these are all distinct from each other.
Find the number of Takahashi's lottery tickets that have a number matching one of the winning numbers.
Constraints
- 1 \leq K \leq 10^5
- 1 \leq M \leq 10^5
- 1 \leq A_i \leq 10^9 (1 \leq i \leq K)
- 1 \leq B_j \leq 10^9 (1 \leq j \leq M)
- A_1, A_2, \ldots, A_K are all distinct
- B_1, B_2, \ldots, B_M are all distinct
- All inputs are integers
Input
K M A_1 A_2 \ldots A_K B_1 B_2 \ldots B_M
- The first line contains the number of winning numbers K and the number of lottery tickets Takahashi has M, separated by a space.
- The second line contains the winning numbers A_1, A_2, \ldots, A_K, separated by spaces.
- The third line contains the numbers on Takahashi's lottery tickets B_1, B_2, \ldots, B_M, separated by spaces.
Output
Print in one line the number of Takahashi's lottery tickets that have a number matching one of the winning numbers.
Sample Input 1
5 3 1 2 3 4 5 2 7 4
Sample Output 1
2
Sample Input 2
4 6 100 200 300 400 150 200 250 300 350 400
Sample Output 2
3
Sample Input 3
10 8 1000000000 999999999 123456789 987654321 555555555 111111111 222222222 333333333 444444444 666666666 123456789 100000000 555555555 777777777 888888888 999999999 12345 67890
Sample Output 3
3