1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4 Public classMain {5 Public Static voidMain (string[] args) {6Scanner Ascanner =NewScanner (system.in);7 intN= Ascanner.nextint ();//read the first one8 LongA[] =New Long[n];//Storing Arrays9 LongB[] =New Long[n];//Alternate ArrayTen One for(inti=0;i<n;i++) A { -A[i] =ascanner.nextint (); - } the intm =ascanner.nextint (); - int[]l =New int[1001]; - int[]r =New int[1001]; - int[]k =New int[1001]; + for(inti=0;i<m;i++) - { +L[i] =ascanner.nextint (); AR[i] =ascanner.nextint (); atK[i] =ascanner.nextint (); - for(intj=l[i]-1;j<r[i];j++) - { -B[J-L[I]+1] =A[j]; - } - Arrays.sort (b); inSystem.out.println (b[b.length-K[i]]); -Arrays.fill (b, ' + ')); to + } - } the}
The two-dimensional array that was used when it was first started, using the bubbling sort, but involved a three-layer loop, and finally though the results came out, the run timed out.
So the need to optimize the method, and then refer to the online standard answer after a sorting function can use the sort () function, directly using the Arrays.sort () function array of small to large order, each time the results are directly output.
At the same time, I need to clear the results after the loop, I use the Arrays.fill () function, with ' "" to fill, but there are insufficient places, will be emptied after the form of 0 exist, the length of the array has not changed, so need me to further improve, the final evaluation results still have a run timeout!! , for informational purposes only
Interval k large number find Java Blue Bridge Cup ALGO-1