Submit | All submissions | Best solutions | Back to list |
NORMA2 - Norma |
Mirko got an array of integers for his birthday from his grandmother Norma. As any other kid, he was hoping for some money, but got an array. Luckily, in his town there is a pawn shop that buys up arrays. The cost of an array of integers is min * max * L kunas, where min is the minimal integer in the array, max is the maximal and L is the array length. Mirko is going to sell a subsequence of consecutive numbers from his array. He calculated the average price of all such subsequences.
In order to check his result, he wants you to do the same. He will be pleased with only the last 9 digits of the sum of all prices, so you don’t need to bother with large and real numbers.
Input
The first line of input contains an integer N (1 ≤ N ≤ 500 000).
Each of the following N lines contains a member of Mirko’s array. The members of the array will be integers from the interval [1, 108].
Output
The first and only line of output must contain an integer, the last 9 digits of the required sum from the task. You don’t need to output the leading zeroes of that 9-digit integer.
Example
Input: 2
1
3 Output: 16
Input:
4
2
4
1
4 Output:
109
Input:
6
8
1
3
9
7
4 Output:
1042
Added by: | Ivan Katanic |
Date: | 2015-01-09 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 JS-MONKEY |
Resource: | COCI 14/15 Round 2 |
hide comments
2018-05-20 10:58:07
cdq! |
|
2018-05-19 05:49:14
uhu,How to solve it! |
|
2015-04-29 12:01:45 Szymon
finally... mod 10^9 everywhere huhhh Last edit: 2015-04-29 15:51:28 |
|
2015-02-16 07:14:24 chamini2
Can you explain the first two examples? I'm not understanding what's the expected answer. RE: 1st sample, we have sequences: {1} => min=1, max=1, len=1 => min*max*len=1 {3} => min=3, max=3, len=1 => min*max*len=9 {1,3} => min=1, max=3, len=2 => min*max*len=6 total of min*max*len is 16. Last edit: 2015-02-16 23:02:14 |
|
2015-01-15 13:28:53 Basudeb Mandal
Got it down to O(N^2), but now wrong answer on test 20 :( Will keep trying :) Last edit: 2015-01-15 13:34:04 |
|
2015-01-11 17:25:59 Basudeb Mandal
TLE on 20th test. Something's not right. :/ RE by ikatanic: Your complexity is not right :). O(N^3) is far too much for N = 500000. Thanks for reply! Yup I know :P Working on it! :) Last edit: 2015-01-15 05:17:27 |