/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高橋君は図書館で働いています。図書館の本棚には N 冊の本が一列に並んでおり、それぞれの本には管理番号が付けられています。左から i 番目(1 \leq i \leq N)の本の管理番号は A_i です。なお、異なる本が同じ管理番号を持つこともあります。
青木君が「管理番号が K の本を探しているのですが、どこにありますか?」と尋ねました。
本棚に並んでいる N 冊の本の中から、管理番号がちょうど K である本を見つけてください。管理番号が K の本が存在する場合は、その本の位置(左から数えて何番目か、1 始まり)のうち最も小さいものを出力してください。存在しない場合は -1 を出力してください。
制約
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- 入力はすべて整数
入力
N K A_1 A_2 \ldots A_N
- 1 行目には、本の冊数を表す整数 N と、探している管理番号を表す整数 K が、スペース区切りで与えられる。
- 2 行目には、各本の管理番号を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
出力
管理番号がちょうど K である本が存在する場合は、その本の位置(左から数えて何番目か、1 始まり)のうち最も小さいものを 1 行で出力せよ。存在しない場合は -1 を出力せよ。
入力例 1
5 3 1 4 3 2 3
出力例 1
3
入力例 2
7 100 50 200 100 100 300 100 400
出力例 2
3
入力例 3
10 999999999 1 1000000000 500000000 123456789 999999999 999999999 777777777 888888888 999999999 1
出力例 3
5
Score : 200 pts
Problem Statement
Takahashi works at a library. On a bookshelf in the library, N books are lined up in a row, and each book has a catalog number assigned to it. The catalog number of the i-th book from the left (1 \leq i \leq N) is A_i. Note that different books may have the same catalog number.
Aoki asks, "I'm looking for the book with catalog number K. Where is it?"
Among the N books on the bookshelf, find the book whose catalog number is exactly K. If a book with catalog number K exists, output the smallest position of such a book (counted from the left, 1-indexed). If no such book exists, output -1.
Constraints
- 1 \leq N \leq 2 \times 10^5
- 1 \leq K \leq 10^9
- 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
- All inputs are integers
Input
N K A_1 A_2 \ldots A_N
- The first line contains an integer N representing the number of books and an integer K representing the catalog number being searched for, separated by a space.
- The second line contains integers A_1, A_2, \ldots, A_N representing the catalog numbers of the books, separated by spaces.
Output
If a book with catalog number exactly K exists, output on a single line the smallest position of such a book (counted from the left, 1-indexed). If no such book exists, output -1.
Sample Input 1
5 3 1 4 3 2 3
Sample Output 1
3
Sample Input 2
7 100 50 200 100 100 300 100 400
Sample Output 2
3
Sample Input 3
10 999999999 1 1000000000 500000000 123456789 999999999 999999999 777777777 888888888 999999999 1
Sample Output 3
5