View Code of Problem 134

#include<iostream>
using namespace std;
#include<algorithm>
struct Node
{
	int data;
	int pos;
};
class Mycompare         //自定义数据类型需要自定标比较 
{
public:
	bool operator()(Node a,Node b)
	{
		return a.data<b.data;
	}	
};
int main()
{
	int n,l,r,q;
	while(scanf("%d",&n)!=EOF)
	{
		Node array[n+1];
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&array[i].data);
			array[i].pos=i;
		}
		sort(array+1,array+n+1,Mycompare());
		scanf("%d",&q);
		while(q--)
		{
			scanf("%d %d",&l,&r);
			for(int i=1;i<=n;i++)
			{
				if(array[i].pos>=l&&array[i].pos<=r)
				{
					printf("%d\n",array[i].data);
					break;
				}
			}
		}

	}
	return 0;
}

Double click to view unformatted code.


Back to problem 134