-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1017.cpp
More file actions
40 lines (40 loc) · 831 Bytes
/
1017.cpp
File metadata and controls
40 lines (40 loc) · 831 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
#include <bits/stdc++.h>
using namespace std;
const int _N = 1000010;
int S[_N];
bool front[_N], back[_N];
main(void) {
cin.tie(0);
ios_base::sync_with_stdio(0);
int T, N;
cin >> T;
while (T--) {
memset(S, 0, sizeof(int) * _N);
memset(front, 0, sizeof(bool) * _N);
memset(back, 0, sizeof(bool) * _N);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
int maxx = S[0];
int minn = S[N - 1];
for (int i = 1; i < N - 1; i++) {
if (S[i] > maxx) {
maxx = S[i];
front[i] = 1;
}
}
for (int i = N - 2; i > 0; i--) {
if (S[i] < minn) {
back[i] = 1;
minn = S[i];
}
}
int _count = 0;
for (int i = 1; i < N - 1; i++) {
if (front[i] && back[i]) _count++;
}
cout << _count << '\n';
}
return 0;
}