#include <bits/stdc++.h>
#define pb push_back
#define tree int h,int l,int r
#define left (h<<1),l,(l+r)>>1
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define f first
#define s second
#define ll long long
using namespace std;
const int N = 2e6 + 5;
int a[N],fen[N];
void upd(int idx){
while (idx <= 2000000){
fen[idx] += 1;
idx += (idx & (-idx));
}
}
int get(int idx){
int s = 0;
while (idx){
s += fen[idx];
idx -= (idx & (-idx));
}
return s;
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++)
cin>>a[i];
int l = 1,ans=0;
while (l <= n){
int r = l,mn = a[l],mx = a[l];
while (r + 1 <= n){
if (a[r + 1] < a[r]) break;
int mn1 = min(mn,a[r + 1]),mx1 = max(mx,a[r + 1]);
if (get(mx1) - get(mn1 - 1) > 0) break;
mn = mn1,mx = mx1;
r++;
}
for (int i = l; i <= r; i++) upd(a[i]);
l = r + 1;
++ans;
}
cout<<ans;
}
/*
4
1 1 1 1
4
1 2 2 1
6
9 6 7 8 1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |