View Code of Problem 134

#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

int main()
{
    int n,q,l,r;
    while(cin >> n){
    pair <int ,int >a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second = i+1;
    }
    sort(a,a + n);
    cin >> q;
    while(q--){
        cin >> l >> r;
        for(int i = 0 ; i < n; i++){
            if(a[i].second >= l && a[i].second <= r){
                cout << a[i].first <<endl;
                break;
            }
        }
    }
    }
    return 0;

}

Double click to view unformatted code.


Back to problem 134