nth_element is a function that allows you to find the nth element in an array in sorted order in linear time.
The function takes the left end of the array, an iterator to the position whose value in sorted order is to be found, and the right end of the array.
After applying the function, the required value will be located at the place indicated by the iterator, while the remaining values will acquire a chaotic order, but to the left of the nth there will be values no more than it, and to the right no less. That is, it should be understood that this function destroys the original order of the elements.
You can read more in the documentation (https://www.cplusplus.com/reference/algorithm/nth_element/).
Example:
vector a = { 4, 0, 3, 9, 2, 1, 8, 5, 6, 7 };
// look for element at index 4
// pay attention to the order of the arguments
nth_element(a.begin(), a.begin() + 4, a.end());
// a = [#, #, #, #, 4, $, $, $, $, $]
// where # <= 4 and 4 <= $