View Code of Problem 134

#include <iostream>
#include <algorithm> 
using namespace std;
struct node{
	int data;
	int pos;
};
node a[100010];
bool cmp(node x,node y){
	return x.data<y.data;
}
int main(){
	int n;
	while(cin>>n){
		for(int i=1;i<=n;i++){
			cin>>a[i].data;
			a[i].pos=i;
		}
		int t;
		cin>>t;
		sort(a+1,a+n+1,cmp);
		while(t--){
			int l,r;
			cin>>l>>r;
			for(int i=1;i<=n;i++){
				if(a[i].pos>=l&&a[i].pos<=r){
					cout<<a[i].data<<endl;
					break;
				}
			}
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 134