270B Multithreading

                                                                                                           B. Multithreading
                                                                                                  time limit per test 2 seconds
                                                                                                  memory limit per test 256 megabytes
                                                                                                  input      standard input
                                                                                                  output     standard output

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 thei-th place in the list there is a thread that was at theai-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 toa1, 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 ofn space-separated integers a1, a2, ...,an whereai (1 ≤ ai ≤ n) is the old position of thei-th thread in the new list. It is guaranteed that all of theai are distinct.

Output

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

Sample test(s)
Input
5
5 2 1 3 4
Output
2
Input
3
1 2 3
Output
0
Input
4
4 3 2 1
Output
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.


想了几天后发现其实这题只需要找一点,从该点到尾部的所有点是按升序排列的,而这点之前的所有点可认为是 变换的得到的。

#include <stdio.h>
#include <string.h>
#include <math.h>
int a[1000000];
int main()
{
    int i,j,n,m,s,t,sta;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
    }
    if(n==1)
    {
        printf("0\n");
    }else
    {
        sta=0;
        for(i=1;i<=n-1;i++)
        {
            if(a[i]<a[i-1])
            {
                sta=i;
            }
        }
        printf("%d\n",sta);
    }
    return 0;
}


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值