eolymp
bolt
Try our new interface for solving problems
Məsələlər

Mountain Holidays

Mountain Holidays

\includegraphics{https://static.e-olymp.com/content/cc/cc8e16bc5a2bfa467eb9cbae910d59025a2d7363.jpg} Some time ago, Chef discovered that more and more people have started climbing mountains every day. So he decided to build restaurant in the Ukrainian resort Bukovel (Carpathian Mountains). But there are many places to choose, so he wants to choose the best one. Let us learn how attractiveness for a location is calculated. Next to every place, is some mountain. A Mountain is a sequence of points \textbf{(0, height_0)}, \textbf{(1, height_1)}, ..., \textbf{(n-1, height_\{n-1\})}. where every two adjacent points are connected with a segment. For example, consider the mountain \textbf{(0, 0) (1, 2) (2, 1) (3, 2) (4, 1) (5, 3) (6, 0) (7, 1) (8, 0)} \includegraphics{https://static.e-olymp.com/content/b2/b26ebca35f4e8cb8071d4de2bfd0fe53a19a5d4b.jpg} Visitors may start their climbing from some position \textbf{i} and finish in position \textbf{j}, where (\textbf{i} < \textbf{j}). They calculate the attractiveness of a mountain, as the number of different climbs that it offers. Of course, so does our Chef! A climb from position \textbf{i} to position \textbf{j} is the sequence \textbf{(i, height_i)}, ..., \textbf{(j, height_j)}. Two climbs, say \textbf{i_1} to \textbf{j_1} and \textbf{i_2} to \textbf{j_2}, are different if and only if \textbf{(j_1-- i_1)} ≠ \textbf{(j_2-- i_2)} or \textbf{(height_\{i1+k\} -- height_\{i1+k-1\})} ≠ \textbf{(height_\{i2+k\} -- height_\{i2+k--1\}) }for at least some \textbf{k} in the range \textbf{\[1..i_1-j_1\]}. Let us consider two climbs from the mountain we considered above \includegraphics{https://static.e-olymp.com/content/0c/0c96128ac87979dc864cc0300cff58cb7ca451a2.jpg} and \includegraphics{https://static.e-olymp.com/content/5a/5a4682830eb2ffa83eed4950c3ce73a20a3ff36a.jpg} The first one is the climb from (\textbf{0} to \textbf{3}), and the second one is the climb from (\textbf{4} to \textbf{6}). They are different because\textbf{(3-0)} ≠ \textbf{(6-4)}. On the other hand, climbs such as (\textbf{0} to \textbf{1}) and (\textbf{4} to \textbf{5}) are the same. Given the array, \textbf{heights}, find the number of different climbs that exist on the mountain which is described by the sequence of these heights. Because answer can be very large, output it modulo \textbf{1000000009}. \InputFile First line of input contains \textbf{Т} -- the number of test cases (\textbf{1} ≤ \textbf{T} ≤ \textbf{1000}). The first line of each test case contains \textbf{N} -- the number of peaks (\textbf{1} ≤ \textbf{N} ≤ \textbf{100000}). On second line of each test case, there are \textbf{N} numbers. The ith number denotes the height of ith peak (\textbf{|Height_i|} ≤ \textbf{10^6}, \textbf{|Height_i}-\textbf{Height_\{i-1\}|} ≤ \textbf{100}). \OutputFile For each test case, output a single number, the number of unique climbs.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3
6
1 2 3 4 5 6
9
0 2 1 2 1 3 0 1 0
7
0 5 -5 5 -5 4 -4
Çıxış verilənləri #1
5
31
20
Müəllif Kozhukhivskiy Vitaliy
Mənbə Distance Summer Computer School - Summer 2013