fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int K = 3;
  13. int[] array = new int[]{5,2,4,6,7};
  14. int[] ret1 = new int[array.length-K+1];
  15. int[] ret2 = new int[array.length-K+1];
  16. for(int i=0;i<=array.length-K;i++){
  17. int count1 = 0; int count2 = 0;
  18. int len1 = 1; int len2 = 1;
  19. for(int j=i;j<i+K-1;j++){
  20. if(array[j]<array[j+1]){
  21. len1++;
  22. }
  23. else{
  24. count1 = count1+(len1*(len1-1)/2);
  25. len1 = 1;
  26. }
  27. }
  28. if(len1 > 1){
  29. count1 = count1+(len1*(len1-1)/2);
  30. }
  31. ret1[i] = count1;
  32. for(int j=i+K-1;j>i;j--){
  33. if(array[j]<array[j-1]){
  34. len2++;
  35. }
  36. else{
  37. count2 = count2+(len2*(len2-1)/2);
  38. len2 = 1;
  39. }
  40. }
  41. if(len2 > 1){
  42. count2 = count2+(len2*(len2-1)/2);
  43. }
  44. ret2[i] = count2;
  45. }
  46. System.out.println(Arrays.toString(ret1));
  47. System.out.println(Arrays.toString(ret2));
  48. }
  49. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
[1, 3, 3]
[1, 0, 0]