#include <stdio.h> #include <stdlib.h> #include <string.h>
typedef struct { int l; int r; int K; } QUERY;
void query(QUERY *q, int *nums) { int i, j, temp; int n = q->r - q->l + 1; int *sec = (int *)malloc(n * sizeof(int)); memcpy(sec, nums + q->l - 1, n * sizeof(int)); for (i = 0; i < n; i++) { for (j = 0; j < n - i - 1; j++) { if (sec[j] < sec[j + 1]) { temp = sec[j]; sec[j] = sec[j + 1]; sec[j + 1] = temp; } } } printf("%d\n", sec[q->K - 1]); free(sec); }
int main() { int i, m, n, *nums; QUERY *qs; scanf("%d", &n); nums = (int *)malloc(n * sizeof(int)); for (i = 0; i < n; i++) scanf("%d", nums + i); scanf("%d", &m); qs = (QUERY *)malloc(m * sizeof(QUERY)); for (i = 0; i < m; i++) scanf("%d%d%d", &qs[i].l, &qs[i].r, &qs[i].K); for (i = 0; i < m; i++) query(qs + i, nums); free(qs); free(nums); return 0; }
|