forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathround656C.cpp
More file actions
52 lines (47 loc) · 803 Bytes
/
Copy pathround656C.cpp
File metadata and controls
52 lines (47 loc) · 803 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
int T, N;
vector<int> ans;
int arr[200000];
int dp[200000];
int dir[200000];
int same[200000];
int main()
{
int i, t;
cin >> T;
for (t = 0; t < T; t++) {
cin >> N;
for (i = 0; i < N; i++) {
dp[i] = 1; dir[i] = 0; same[i] = 1;
}
for (i = 0; i < N; i++) {
cin >> arr[i];
}
for (i = 1; i < N; i++) {
if (arr[i] > arr[i - 1]) {
if (dir[i - 1] == -1) {
dp[i] = same[i - 1] + 1;
}
else {
dp[i] = dp[i - 1] + 1;
}
}
else if (arr[i] == arr[i - 1]) {
dp[i] = dp[i - 1] + 1;
dir[i] = dir[i - 1];
same[i] = same[i - 1] + 1;
}
else {
dp[i] = dp[i - 1] + 1;
dir[i] = -1;
}
}
ans.push_back(N-dp[N - 1]);
}
for (int i : ans) {
cout << i << "\n";
}
return 0;
}