#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], bit[MAXN], N, l, r;
pii b[MAXN];
int query(int idx) {
int rez = 0;
while(idx) {
rez += bit[idx];
idx -= idx&-idx;
}
return rez;
}
void update(int idx, int val) {
while(idx < MAXN) {
bit[idx] += val;
idx += idx&-idx;
}
}
int main() {
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
for(int i = 1; i <= N; i++) b[i] = {a[i], i};
sort(b+1, b+1+N);
for(int i = 1; i <= N; i++) a[b[i].se] = i;
for(int i = 1; i <= N; i++) update(i, +1);
int rez = 1;
update(a[1], -1);
for(int i = 2; i <= N; i++) {
update(a[i], -1);
if(a[i-1] > a[i] || query(a[i]-1)-query(a[i-1]) != a[i]-a[i-1]-1) rez++;
}
cout << rez;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |