#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 = 1e6 + 5;
int a[N],fen[N];
void upd(int idx){
while (idx <= 1000000){
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;
r++;
}
for (int i = l; i <= r; i++) upd(a[i]);
l = r + 1;
++ans;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |