View Code of Problem 134

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;

struct S{
	long long num;
	int id;
};

bool cmp(S a,S b){
	return a.num < b.num;
}

int main(void){
	int n;
	vector<S> v;
	while(~scanf("%lld",&n)){
		v.clear();
		S s;
		for(int i = 1;i <= n;i++){
			scanf("%lld",&s.num);
			s.id = i;
			v.push_back(s);
		}
		sort(v.begin(),v.end(),cmp);
		int q;
		scanf("%d",&q);
		for(int i = 0;i < q;i++){
			int a,b;
			scanf("%d %d",&a,&b);
			int j;
			for(j = 0;j < n;j++){
				if(v[j].id >= a && v[j].id <= b)
					break;
			}
			printf("%lld\n",v[j].num);
	}
	}
	
}

Double click to view unformatted code.


Back to problem 134