DCEPCA09 - MMM
Everyone knows how to find mean, median and mode of an array of numbers. For people who don’t know this, here is the description:
Mean is the arithmetic average of a set of values.
Median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle one. If there is an even number of observations, then there is no single middle value; the median is then usually defined to be the mean of the two middle values.
The mode is the value that appears most often in a set of data. If more than one number is applicable to be the mode, select the highest value number amongst them as the mode.
The problem is just to find these 3 values. Given an array of numbers and two indices i and j , find the mean , median and mode of elements in the interval i to j including numbers at indices i and j. Note that i and j are 0 index based.
2 <= N <= 10000
1 <= Q <= 10000
0 <= A[i] <= 10^8
0 <= i < N
i <= j < N
First line contains N which is the total number of numbers in the array. The next line contains N numbers A[i] which are the elements of the array. Next line contains a number Q which defines the total number of queries we are making for the interval i to j. It is followed by Q lines each containing 2 numbers i and j which denotes the indices to be queried for.
Print Q lines each containing 3 numbers Mean, Median and Mode respectively. If the answer for any case comes to be a floating point, then take the integer part of the number as the answer.
For example: if mean, median and mode comes up to be 6.44 7.8 9 then the final answer is 6 7 9.
6 5 3 7 7
Output: 4 4 5
5 6 7
O(n*sqrt(n*log(n))) works fine, even using fast i/o methods.
Getting TLE. Used STL's Unordered_Map and Min-Max Heaps. Would their customized implementations do the job or am I missing some trick :-?
my code is running well and good on ideone but here i am getting a RE after 7th case!Last edit: 2012-12-26 00:03:30
problem code: 8257109
Kunal, when you get a RE, it stops running the cases. But the display still shows them all. You could be failing after the 1st or 2nd, or however many cases.
@dce coders:-how many cases dude...getting sigsegv after 14th case!!!what may be the problem???
|Added by:||dce coders|
|Cluster:||Cube (Intel G860)|
|Languages:||ASM32-GCC MAWK BC C-CLANG C C++ 4.3.2 CPP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JAVA JS-MONKEY KTLN NIM OBJC OBJC-CLANG OCT PICO PROLOG PYPY R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET|