View Code of Problem 134

#include<iostream>
#include<algorithm>
using namespace std;
struct num{
	int n;
	int p;
}nums[100003]; 
int cmp(num a,num b){
	return a.n<b.n;
}

int main(int argc, char *argv[])
{
	int n,q;
	while(scanf("%d",&n)!=EOF){ 
	for(int i =0;i<n;i++){
		scanf("%d",&nums[i].n);
		nums[i].p= i+1;
	}
	sort(nums,nums+n,cmp);
	scanf("%d",&q);
	while(q--){
		int a,b;
		scanf("%d %d",&a,&b);
		for(int i=0;i<n;i++){
			if(nums[i].p>=a&&nums[i].p<=b){
				printf("%d\n",nums[i].n);
				break;
			}
		}
		
	}
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 134