前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >codeforce 270B Multithreading

codeforce 270B Multithreading

作者头像
风骨散人Chiam
发布2020-10-28 10:18:50
2900
发布2020-10-28 10:18:50
举报
文章被收录于专栏:CSDN旧文

B. Multithreading

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?ai-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?a1,?a2, ...,?an.

Input

The first line of input contains an integer?n, the number of threads (1?≤?n?≤?105). The next line contains a list of?n?space-separated integers?a1,?a2, ...,?an?where?ai?(1?≤?ai?≤?n) is the old position of the?i-th thread in the new list. It is guaranteed that all of the?ai?are distinct.

Output

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

Examples

input

代码语言:javascript
复制
5
5 2 1 3 4

output

代码语言:javascript
复制
2

input

代码语言:javascript
复制
3
1 2 3

output

代码语言:javascript
复制
0

input

代码语言:javascript
复制
4
4 3 2 1

output

代码语言:javascript
复制
3

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.

水~~

代码语言:javascript
复制
#include<iostream>
using namespace std;
int a[100005];
int main(){
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];

    }
    for(int i=1;i<=n-1;i++)
        if(a[i]>a[i+1])sum=i;
    cout<<sum<<endl;


}
本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com