Emiliatan

b684

Mar 11th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. /* b684             */
  2. /* AC (0.1s, 3.9MB) */
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. const int MAXN = 1000001;
  8. const bool toward = true, backward = false;
  9.  
  10. int n, ans = 0, nowPos = 1;
  11. bool dir = toward;
  12. int card[MAXN];
  13.  
  14. int main()
  15. {
  16.     scanf("%d", &n);
  17.     for(int i = 1, num; i <= n; card[num] = i, i++) scanf("%d", &num);
  18.     for(int i = 1; i <= n; nowPos = card[i], i++)
  19.     {
  20.         if(nowPos <= card[i])
  21.             ans += (dir != toward), dir = toward;
  22.         else
  23.             ans += (dir != backward), dir = backward;
  24.     }
  25.     printf("%d",ans);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment