Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int n;
- scanf("%d",&n);
- vector <int> num{0};
- set <int> keep;
- for(int i=1;i<=n;i++){
- int x;
- scanf("%d",&x);
- num.push_back(x);
- }
- int s = 1, e = n, cnt = 0;
- for(int j=1;j<=n;j++){
- int x;
- if(j%2 == 1) {
- x = s;
- s++;
- }
- else {
- x = e;
- e--;
- }
- if(num[x] == x) {
- cnt++;
- continue;
- }
- for(int j=1;j<=n;j++){
- if(num[j] == x){
- num.erase(num.begin()+j);
- num.insert(num.begin()+x,x);
- break;
- }
- }
- }
- printf("%d",cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement