Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* b684 */
- /* AC (0.1s, 3.9MB) */
- #include <cstdio>
- using namespace std;
- const int MAXN = 1000001;
- const bool toward = true, backward = false;
- int n, ans = 0, nowPos = 1;
- bool dir = toward;
- int card[MAXN];
- int main()
- {
- scanf("%d", &n);
- for(int i = 1, num; i <= n; card[num] = i, i++) scanf("%d", &num);
- for(int i = 1; i <= n; nowPos = card[i], i++)
- {
- if(nowPos <= card[i])
- ans += (dir != toward), dir = toward;
- else
- ans += (dir != backward), dir = backward;
- }
- printf("%d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment