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
#include<bits/stdc++.h>

using namespace std;

int infi=10e9;
int arr1[50010];
int arr2[50010];

int main(){
    int n;
    cin >> n;
    arr1[0]=infi*-1;
    arr2[0]=infi;
    for(int i=1;i<=n;i++){
        cin >> arr1[i];
        arr2[i]=arr1[i];
    }
    int ans1=0,ans2=0;
    for(int i=1;i<=n;i++){
        if(i&1){
            if(arr1[i]<=arr1[i-1]){
                arr1[i]=infi;
                ans1++;
            }
            if(arr2[i]>=arr2[i-1]){
                arr2[i]=infi*-1;
                ans2++;
            }
        } else {
            if(arr1[i]>=arr1[i-1]){
                arr1[i]=infi*-1;
                ans1++;
            }
            if(arr2[i]<=arr2[i-1]){
                arr2[i]=infi;
                ans2++;
            }
        }
    }
    cout << min(ans1,ans2) << "\n";
    return 0;
}