Codeforces Round 165 (Div. 2)
B
Multithreading
Codeforces
1400
原题
← AC →
翻译中…

Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.

翻译中…

Recent actions shows a list of $*n*$ different threads ordered by the time of the latest message in the thread. When a new message is posted in a thread that thread jumps on the top of the list. No two messages of different threads are ever posted at the same time.

翻译中…

Emuskald has just finished reading all his opened threads and refreshes the main page for some more messages to feed his addiction. He notices that no new threads have appeared in the list and at the $*i*$-th place in the list there is a thread that was at the $*a*_{*i*}$-th place before the refresh. He doesn't want to waste any time reading old messages so he wants to open only threads with new messages.

翻译中…

Help Emuskald find out the number of threads that surely have new messages. A thread $*x*$ surely has a new message if there is no such sequence of thread updates (posting messages) that both conditions hold:

翻译中…
  1. thread $*x*$ is not updated (it has no new messages);
  2. the list order 1, 2, ..., $*n*$ changes to $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$.
翻译中…

Input

翻译中…

The first line of input contains an integer $*n*$, the number of threads ($1 ≤ *n* ≤ 10^{5}$). The next line contains a list of $*n*$ space-separated integers $*a*_{1}$, $*a*_{2}$, ..., $*a*_{*n*}$ where $*a*_{*i*}$ ($1 ≤ *a*_{*i*} ≤ *n*$) is the old position of the $*i*$-th thread in the new list. It is guaranteed that all of the $*a*_{*i*}$ are distinct.

翻译中…

Output

翻译中…

Output a single integer — the number of threads that surely contain a new message.

翻译中…

Note

翻译中…

In the first test case, threads 2 and 5 are placed before the thread 1, so these threads must contain new messages. Threads 1, 3 and 4 may contain no new messages, if only threads 2 and 5 have new messages.

翻译中…

In the second test case, there may be no new messages at all, since the thread order hasn't changed.

翻译中…

In the third test case, only thread 1 can contain no new messages.

翻译中…

样例

Input #1
5
5 2 1 3 4
Output #1
2
InputCopy OutputCopy
Input #2
3
1 2 3
Output #2
0
InputCopy OutputCopy
Input #3
4
4 3 2 1
Output #3
3
InputCopy OutputCopy
题目信息
题号
270B
时间限制
2 s
内存限制
256 MB
标签
数据结构
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。