View Code of Problem 134

#include <stdio.h>
#include <algorithm>
using namespace std;

 struct node
 {
	 int data;
	 int order;
 }s[110000];

 bool cmp(struct node a,struct node b)
{
	return a.data<b.data;
}
int main()
{
	 int i,n,q,l,r;
	 while(scanf("%d",&n)!=EOF)
	 {
		 for(i=0;i<n;i++)
		 {
			 scanf("%d",&s[i].data);
			 s[i].order=i+1;
		 }
		 scanf("%d",&q);
		 sort(s,s+n,cmp);
		 while(q--)
		 {
			 scanf("%d%d",&l,&r);
			 for(i=0;i<n;i++)
				 if(s[i].order>=l&&s[i].order<=r)
				 {printf("%d\n",s[i].data);break;}
		 }
	 }
	 return 0;
}

Double click to view unformatted code.


Back to problem 134