fork download
  1. import java.util.*;
  2.  
  3.  
  4. public class Main
  5. {
  6. public static void main(String[] args)
  7. {
  8. Scanner in = new Scanner(System.in);
  9. int n = in.nextInt();
  10. int k = in.nextInt();
  11. int[] elem_tree = new int[n];
  12. int ans=0, left=0, right=0;
  13. for(int i=0; i<n; i++){
  14. elem_tree[i]=in.nextInt();
  15. if (elem_tree[i]==k){
  16. ans+=i-left+1;
  17. right=i;
  18. }
  19. else{
  20. if(elem_tree[i]>k){
  21. right=0;
  22. left=i+1;
  23. }
  24. else if(elem_tree[i]<k && right!=0) ans+=right-left+1;
  25. }
  26. }
  27. System.out.println(ans);
  28. }
  29. }
Success #stdin #stdout 0.07s 29384KB
stdin
20 15
5 2 4 7 15 3 15 20 31 15 15 1 23 4 8 15 1 2 15 6
stdout
43