-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1346.cpp
92 lines (76 loc) · 1.35 KB
/
1346.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int rec[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b;cin>>a>>b;
int n=b-a+1;
for(int i=0;i<n;++i)
{
cin>>rec[i];
}
int cur=0,prev=rec[0];
int ans=0;
for(int i=1;i<n;++i)
{
int x=rec[i];
if(cur==0)
{
if(x>prev)
{
cur=1;
prev=x;
}
else if(x<prev)
{
cur=2;
prev=x;
}
}
else if(cur==1)
{
if(x>prev)
{
prev=x;
}
else if(x<prev)
{
++ans;
cur=0;
prev=x;
}
}
else if(cur==2)
{
if(x<prev)
{
prev=x;
}
else if(x>prev)
{
++ans;
cur=0;
prev=x;
}
}
}
cout<<ans+1<<'\n';
}