#include <bits/stdc++.h>
#define MAXN 1000010
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
using namespace std;
int a[MAXN], inv[MAXN], N, l, r;
int L[MAXN], R[MAXN];
pii b[MAXN];
vector<pii> seg;
int main() {
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) b[i-1] = {a[i], i};
sort(b, b+N);
for(int i = 0; i < N; i++) a[b[i].se] = i+1;
l = r = a[1];
for(int i = 2; i <= N+1; i++) {
if(a[i] == r+1) {
r++;
} else {
seg.pb({l, r});
l = r = a[i];
}
}
int rez = 1;
R[N+1] = N+1;
while(!seg.empty()) {
pii vrh = seg.back(); seg.pop_back();
l = vrh.fi, r = vrh.se;
if(R[r+1]) r = R[r+1];
if(L[l-1]) l = L[l-1];
while(!seg.empty()) {
pii vrh = seg.back();
if(vrh.se+1 == l) {
l = vrh.fi;
seg.pop_back();
} else break;
}
if(r != N+1) {
L[r] = l; R[l] = r;
rez++;
}
}
cout << rez;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |