oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

slopes Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

slopes.html

Problem Description

Gug has a random array A of length N. A subarray of A is defined as a slope if all its elements, when read from left to right, are in strictly ascending or strictly descending order.

Gug, for some reason, wants to cut A into smaller consecutive subarrays, such that each of these subarrays is a slope. Help him find the minimum number of cuts he has to make for this to happen.

Limits

For all tests: 1 ≤ Ai ≤ 109.

Subtask 1 (22%): 1 ≤ N ≤ 1000.

Subtask 2 (24%): 1 ≤ N ≤ 200000, 1 ≤ Ai ≤ 2.

Subtask 3 (26%): 1 ≤ N ≤ 200000, Ai ≠ Aj if i ≠ j.

Subtask 4 (28%): 1 ≤ N ≤ 200000.

Subtask 5 (0%): Sample Testcases.

Input

The first line of input will contain one integer, N.

The second line of input will contain N integers, representing the array A.

Output

The only line of output should contain one integer, the minimum number of cuts Gug has to make.

Sample Testcase 1

Input

5
9 5 3 2 1

Output

0

Sample Testcase 2

Input

5
1 2 3 2 1

Output

1

Sample Testcase 3

Input

6
1 2 3 3 2 1

Output

1

Tags

Greedy

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
122230.5s256MBMinimum
224200.5s256MBMinimum
326210.5s256MBMinimum
428830.5s256MBMinimum
5030.5s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o slopes -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.