/* Murad Eynizade */
#include <bits/stdc++.h>
#define intt long long
#define FAST_READ ios_base::sync_with_stdio(0);cin.tie(0);
#define SIZE 1000001
#define INF INT_MAX
#define F first
#define S second
#define in(a) scanf("%d",&a);
#define outn(a) printf("%d\n",&a);
#define outs(a) printf("%d ",&a);
#define MOD 1000000007
using namespace std;
int n , a[SIZE] , co = 1 , tree[4 * SIZE];
void update(int v,int l,int r,int in) {
if (l == r) {
tree[v] = 1;
return;
}
int m = (l + r) >> 1;
if (in <= m)update(v << 1,l,m,in);
else update(v << 1 | 1,m + 1,r,in);
tree[v] = tree[v << 1] + tree[v << 1 | 1];
}
int getans(int v,int l,int r,int le,int ri) {
if (l > ri || r < le)return 0;
if (l >= le && r <= ri)return tree[v];
int m = (l + r) >> 1;
return getans(v << 1,l,m,le,ri) + getans(v << 1 | 1,m + 1,r,le,ri);
}
int main()
{
FAST_READ;
cin>>n;
for (int i = 1;i<=n;i++)cin>>a[i];
int f = 1;
for (int i = 2;i<=n;i++) {
if (a[i] < a[i - 1]) {
//cout<<i<<endl;
int in = i - 1;
while (in >= f) {
update(1,1,SIZE - 1,a[in]);
in--;
}
f = i;
co++;
}
else if (getans(1,1,SIZE - 1,a[f],a[i]) - getans(1,1,SIZE - 1,a[f],a[f]) - getans(1,1,SIZE - 1,a[i],a[i]) > 0) {
//cout<<i<<" --- "<<endl;
int in = i - 1;
while (in >= f) {
update(1,1,SIZE - 1,a[in]);
in--;
}
f = i;
co++;
}
}
cout<<co<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
3 ms |
812 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
948 KB |
Output is correct |
20 |
Correct |
2 ms |
948 KB |
Output is correct |
21 |
Correct |
2 ms |
948 KB |
Output is correct |
22 |
Correct |
2 ms |
948 KB |
Output is correct |
23 |
Correct |
2 ms |
948 KB |
Output is correct |
24 |
Correct |
2 ms |
948 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
3 ms |
812 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
948 KB |
Output is correct |
20 |
Correct |
2 ms |
948 KB |
Output is correct |
21 |
Correct |
2 ms |
948 KB |
Output is correct |
22 |
Correct |
2 ms |
948 KB |
Output is correct |
23 |
Correct |
2 ms |
948 KB |
Output is correct |
24 |
Correct |
2 ms |
948 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
27 |
Correct |
2 ms |
1168 KB |
Output is correct |
28 |
Correct |
2 ms |
1168 KB |
Output is correct |
29 |
Correct |
2 ms |
1168 KB |
Output is correct |
30 |
Correct |
2 ms |
1168 KB |
Output is correct |
31 |
Correct |
2 ms |
1168 KB |
Output is correct |
32 |
Correct |
2 ms |
1168 KB |
Output is correct |
33 |
Correct |
2 ms |
1168 KB |
Output is correct |
34 |
Correct |
2 ms |
1168 KB |
Output is correct |
35 |
Correct |
2 ms |
1168 KB |
Output is correct |
36 |
Correct |
3 ms |
1168 KB |
Output is correct |
37 |
Correct |
5 ms |
3264 KB |
Output is correct |
38 |
Correct |
4 ms |
3264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
508 KB |
Output is correct |
3 |
Correct |
2 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
644 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
2 ms |
720 KB |
Output is correct |
9 |
Correct |
2 ms |
748 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
748 KB |
Output is correct |
12 |
Correct |
2 ms |
748 KB |
Output is correct |
13 |
Correct |
2 ms |
748 KB |
Output is correct |
14 |
Correct |
2 ms |
752 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
808 KB |
Output is correct |
17 |
Correct |
3 ms |
812 KB |
Output is correct |
18 |
Correct |
2 ms |
948 KB |
Output is correct |
19 |
Correct |
2 ms |
948 KB |
Output is correct |
20 |
Correct |
2 ms |
948 KB |
Output is correct |
21 |
Correct |
2 ms |
948 KB |
Output is correct |
22 |
Correct |
2 ms |
948 KB |
Output is correct |
23 |
Correct |
2 ms |
948 KB |
Output is correct |
24 |
Correct |
2 ms |
948 KB |
Output is correct |
25 |
Correct |
2 ms |
1164 KB |
Output is correct |
26 |
Correct |
2 ms |
1168 KB |
Output is correct |
27 |
Correct |
2 ms |
1168 KB |
Output is correct |
28 |
Correct |
2 ms |
1168 KB |
Output is correct |
29 |
Correct |
2 ms |
1168 KB |
Output is correct |
30 |
Correct |
2 ms |
1168 KB |
Output is correct |
31 |
Correct |
2 ms |
1168 KB |
Output is correct |
32 |
Correct |
2 ms |
1168 KB |
Output is correct |
33 |
Correct |
2 ms |
1168 KB |
Output is correct |
34 |
Correct |
2 ms |
1168 KB |
Output is correct |
35 |
Correct |
2 ms |
1168 KB |
Output is correct |
36 |
Correct |
3 ms |
1168 KB |
Output is correct |
37 |
Correct |
5 ms |
3264 KB |
Output is correct |
38 |
Correct |
4 ms |
3264 KB |
Output is correct |
39 |
Correct |
233 ms |
6152 KB |
Output is correct |
40 |
Correct |
376 ms |
12896 KB |
Output is correct |
41 |
Correct |
199 ms |
13612 KB |
Output is correct |
42 |
Correct |
187 ms |
16064 KB |
Output is correct |
43 |
Correct |
123 ms |
17368 KB |
Output is correct |
44 |
Correct |
456 ms |
26932 KB |
Output is correct |
45 |
Correct |
448 ms |
33472 KB |
Output is correct |
46 |
Correct |
452 ms |
40432 KB |
Output is correct |
47 |
Correct |
518 ms |
47240 KB |
Output is correct |
48 |
Correct |
489 ms |
54124 KB |
Output is correct |
49 |
Correct |
698 ms |
68876 KB |
Output is correct |
50 |
Correct |
696 ms |
75712 KB |
Output is correct |
51 |
Correct |
700 ms |
82512 KB |
Output is correct |
52 |
Correct |
668 ms |
89244 KB |
Output is correct |
53 |
Correct |
659 ms |
96044 KB |
Output is correct |
54 |
Correct |
677 ms |
102700 KB |
Output is correct |
55 |
Correct |
870 ms |
109456 KB |
Output is correct |
56 |
Correct |
850 ms |
116352 KB |
Output is correct |
57 |
Correct |
850 ms |
122952 KB |
Output is correct |
58 |
Correct |
846 ms |
129696 KB |
Output is correct |
59 |
Correct |
900 ms |
136440 KB |
Output is correct |
60 |
Correct |
856 ms |
143188 KB |
Output is correct |
61 |
Correct |
894 ms |
149868 KB |
Output is correct |
62 |
Correct |
958 ms |
156744 KB |
Output is correct |