--------------------------------------------------------------------------
数组也有sort方法
尽量把输入和操作分开写
--------------------------------------------------------------------------
1 import java.util.*; 2 public class Main { 3 public static void main(String[] args) { 4 Scanner sc = new Scanner(System.in); 5 int n = sc.nextInt(); 6 int[] a = new int[n]; 7 for(int i=0;i<n;i++) 8 a[i] = sc.nextInt(); 9 int m = sc.nextInt(); 10 int[] l = new int[m]; 11 int[] r = new int[m]; 12 int[] K = new int[m]; 13 for(int i=0;i<m;i++) { 14 l[i] = sc.nextInt(); 15 r[i] = sc.nextInt(); 16 K[i] = sc.nextInt(); 17 } 18 int[] res = new int[m]; 19 for(int i=0;i<m;i++) { 20 int[] b = new int[r[i]-l[i]+1]; 21 int w = l[i] - 1; 22 for(int j=0,k=w;j<b.length;j++,k++) 23 b[j] = a[k]; 24 Arrays.sort(b); 25 res[i] = b[b.length-K[i]]; 26 } 27 for(int i:res) 28 System.out.println(i); 29 } 30 }