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>
using namespace std;
const int inf = 1e9;
int main(){
    ios_base :: sync_with_stdio(0);
    int n,res1=0,res2=0,last1,last2; cin >> n >> last1;
    last2 = last1;
    for(int i = 1; i < n; i++){
        int a; cin >> a;
        if(i % 2 == 1){
            if(a >= last1)
                res1++,last1 = -inf;
            else
                last1 = a;
            if(a <= last2)
                res2++,last2 = inf;
            else
                last2 = a;
        }
        else{
            if(a <= last1)
                res1++,last1 = inf;
            else
                last1 = a;
            if(a >= last2)
                res2++,last2=-inf;
            else
                last2 = a;
        }
    }cout << min(res1,res2) << "\n";
}