hiho week 208 register

Ended

Participants:101

Verdict:Accepted
Score:100 / 100
Submitted:2018-06-24 23:39:50

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <string>
#include <vector>
#include <set>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=100000+10;
typedef long long  ll;
int a[maxn],b[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    int p=0,q=n-1;
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]==b[i]) p++;
        else break;
    }
    for(int i=n-1;i>=0;i--){
        if(a[i]==b[i]) q--;
        else break;
    }
    cout<<q-p+1<<endl;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX