View Code of Problem 134

#include <iostream>
#include <algorithm>
using namespace std;
typedef struct{
	int a,b;
}node;
bool cmp(node a,node b){
	return a.a<b.a;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		node a[n+1]={0};
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i].a);
			a[i].b=i;
		}
		sort(a+1,a+1+n,cmp);
		int m;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			int t1,t2;
			scanf("%d %d",&t1,&t2);
			for(int i=1;i<=n;i++){
				if(a[i].b>=t1&&a[i].b<=t2){
                                  	printf("%d\n",a[i].a);
					break;
				}
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 134