View Code of Problem 134

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
bool cmp(struct node x, struct node y);

struct node
{
	long long value;
	int seq;
}nod[100002];

int main()
{
	int n;
	int q, l, r;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> nod[i].value;
		nod[i].seq = i;
	}
	stable_sort(nod+1, nod+n+1, cmp);
	cin >> q;
	while(q--)
	{
		cin >> l >> r;
		for(int i = 1; i <= n; i++)
			if(nod[i].seq >= l && nod[i].seq <= r)
			{
				cout << nod[i].value << endl;
				break;
			}
	}
	return 0;
}

bool cmp(struct node x, struct node y)
{
	return x.value <= y.value;
}

Double click to view unformatted code.


Back to problem 134