PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000015. Đếm đội ba người hợp lệ (Count Number of Teams)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đội ba người hợp lệ (Count Number of Teams)
Count Number of Teams
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
There are people standing in a line, each with a distinct rating. Choose positions . A team is valid when the ratings are strictly increasing () or strictly decreasing (). Count all valid teams; a person may belong to several teams.
Input
The first line contains the number of people in a row. The next line contains their ratings in standing order.
Output
Print one integer: the number of valid three-person teams.
Subtasks
- Subtask 1 (20 points): ; for every ; all are pairwise distinct.
- Subtask 2 (30 points): ; for every ; all are pairwise distinct.
- Subtask 3 (50 points): ; for every ; all are pairwise distinct.
Examples
Input
5
2 5 3 4 1
Output
3
Explanation
The increasing team has ratings . The decreasing teams have ratings and . No other ordered triple is strictly monotone, giving teams.