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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
using namespace std;

const int mx=1000001,mi=-1000001;

int arr[50000][3];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,out1=0,out2=0;
    cin>>n>>arr[0][0];
    arr[0][1]=arr[0][0];
    arr[0][2]=arr[0][0];
    for(int i=1;i<n;i++){
        cin>>arr[i][0];
        arr[i][1]=arr[i][0];
        arr[i][2]=arr[i][0];
        if(i%2==1){
            if(arr[i][0]>=arr[i-1][1]){
                arr[i][1]=mi;
                out1++;
            }
            if(arr[i][0]<=arr[i-1][2]){
                arr[i][2]=mx;
                out2++;
            }
        }
        else{
            if(arr[i][0]<=arr[i-1][1]){
                arr[i][1]=mx;
                out1++;
            }
            if(arr[i][0]>=arr[i-1][2]){
                arr[i][2]=mi;
                out2++;
            }
        }
    }
    out1=min(out1,out2);
    cout<<out1;
    return 0;
}