CF653C.Bear and Up-Down
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The life goes up and down, just like nice sequences. Sequence _t_1, _t_2, ..., t__n is called nice if the following two conditions are satisfied:
- t__i < t__i + 1 for each odd i < n;
- t__i > t__i + 1 for each even i < n.
For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.
Bear Limak has a sequence of positive integers _t_1, _t_2, ..., t__n. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements t__i and t__j in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.
人生有起有落,恰如“优美序列”。序列 t1, t2, ..., tn 被称为优美序列,当且仅当满足以下两个条件:
- 对每个奇数 i<n,有 ti<ti+1;
- 对每个偶数 i<n,有 ti>ti+1。
例如,序列 (2, 8)、(1, 5, 1) 和 (2, 5, 1, 100, 99, 120) 是优美的,而 (1, 1)、(1, 2, 3) 和 (2, 5, 3, 2) 则不是。
熊 Limak 有一个正整数序列 t1, t2, ..., tn。当前该序列并不优美,Limak 希望通过恰好一次交换来修复它:他将选择两个下标 i<j,并交换元素 ti 和 tj,使得所得序列为优美序列。请计算满足条件的交换方案数。若两次交换所选元素的下标不同,则视为不同的方案。
输入格式
The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.
The second line contains n integers _t_1, _t_2, ..., t__n (1 ≤ t__i ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.
输入的第一行包含一个整数 n(2≤n≤150000)—— 序列的长度。
第二行包含 n 个整数 t1,t2,...,tn(1≤ti≤150000)—— 初始序列。保证给定的序列不是“好”的(nice)。
输出格式
Print the number of ways to swap two elements exactly once in order to get a nice sequence.
恰好交换两个元素,使得序列变为“好序列”的方案数。
输入输出样例
输入#1
5 2 8 4 7 7
输出#1
2
输入#2
4 200 150 100 50
输出#2
1
输入#3
10 3 2 1 4 1 4 1 4 1 4
输出#3
8
输入#4
9 1 2 3 4 5 6 7 8 9
输出#4
0
说明/提示
In the first sample, there are two ways to get a nice sequence with one swap:
- Swap _t_2 = 8 with _t_4 = 7.
- Swap _t_1 = 2 with _t_5 = 7.
In the second sample, there is only one way — Limak should swap _t_1 = 200 with _t_4 = 50.
在第一个样例中,存在两种通过一次交换得到优美序列的方法:
- 交换 t2=8 与 t4=7。
- 交换 t1=2 与 t5=7。
在第二个样例中,仅有一种方法——Limak 应交换 t1=200 与 t4=50。
输入解题思路,AI测评打分。不知道怎么写?