303367: CF653C. Bear and Up-Down
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Bear and Up-Down
题意翻译
人生起起落落,就像令人愉快的序列。只要满足了以下两种条件,序列$t1$,$t2$,...,$tn$就叫做令人愉快的: - 对于每一个奇数$i(i<n)$有$ti<ti+1$; - 对于每一个偶数$i(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)$就不是。 Bear Limak有一个正整数序列$t1$,$t2$,...,$tn$。现在这个序列**不是令人愉快的**,Limak想要通过一次交换来修改它。他将要选择两个指数$i<j$然后交换他们的元素$ti$和$tj$从而得到一个令人愉快的序列。数数有多少种方法可以得到。如果交换的两个元素的指数不同则认为这是两种不同的方法。 **输入格式** 输入的第一行包含一个整数$n$$(2≤n≤150000)$代表虚列的长度。 第二行包含$n$个整数$t1$,$t2$,...,$tn$$(1≤ti≤150000)$代表初始的序列。可以保证的是所给的序列一定不令人愉快。 **输出格式** 输出想要得到一个令人愉快的序列有多少种方法来交换两个元素。 **提示/说明** 在第一个样例中,有两种方式通过一次交换得到一个令人满意的序列: 1. 交换$t2=8$和$t4=7$。 1. 交换$t1=2$和$t5=7$。 在第二个样例中,只有一种方式—Limak应该交换$t1=200$和$t4=50$。题目描述
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.输入输出格式
输入格式
The first line of the input contains one integer $ n $ ( $ 2<=n<=150000 $ ) — the length of the sequence. The second line contains $ n $ integers $ t_{1},t_{2},...,t_{n} $ ( $ 1<=t_{i}<=150000 $ ) — the initial sequence. It's guaranteed that the given sequence is not 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