#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 1e6+10;
int n;
int arr[mxn],pos[mxn],bit[mxn];
bitset<mxn> done;
int sh = 0;
int ans = 0;
void modify(int p,int v){
for(;p<mxn;p+=p&-p)bit[p] += v;
return;
}
int getval(int p){
int re = 0;
for(;p>0;p-= p&-p)re += bit[p];
return re;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i = 1;i<=n;i++){
cin>>arr[i];
pos[arr[i]] = i;
}
for(int i = n;i>=1;i--){
int p = pos[i];
if(p == n||arr[p+1]-getval(arr[p+1]) != i+1)ans++;
else{
if(!done[p+1])done[p+1] = true,modify(arr[p+1],1);
done[p] = true,modify(i,1);
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |