#CCBCHBA0000061. Kiểm số thứ tự kết thúc (Last Occurrence Position)
Kiểm số thứ tự kết thúc (Last Occurrence Position)
Last Occurrence Position
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a target x and n integers, output the last 1-based position containing x. If x never occurs, or n=0, output -1. Process values as a stream.
Input
The first line contains n and x (0<=n<=100000; x is a signed 32-bit integer). Exactly n signed 32-bit integers follow.
Output
Print the last 1-based position, or -1 if absent.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): và mọi giá trị thuộc miền
int32 bit.
Examples
Example 1
Input:
5 2
2 3 2 4 2
Output:
5
Explanation:
The target appears at positions 1, 3, and 5; the last is 5.
Example 2
Input:
0 -4
Output:
-1
Explanation:
No elements are present.