View Code of Problem 134

#include<iostream>
#include<vector>
#include<algorithm> 
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.second < b.second;
}
int main() {
	int n, t, a, b;
	while (cin >> n) {
		vector<pair<int, int>> pr(n);
		for (int i = 0; i < n; i++) {
			pr[i].first = i + 1;
			scanf("%d", &pr[i].second);
		}
		sort(pr.begin(), pr.end(), cmp);
		cin >> t;
		while (t--) {
			scanf("%d %d", &a, &b);
			for (int i = 0; i < n; i++)
				if (pr[i].first >= a && pr[i].first <= b) {
					printf("%d\n", pr[i].second );
					break;
				}
		}
	}
}

Double click to view unformatted code.


Back to problem 134