View Code of Problem 134

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

using namespace std;
bool cmp(struct data a, struct data b){


	return a.value < b.value;

}
struct data
{
	int value;
	int seq;
}num[100002];

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



/*
Main.cc:6:22: error: 'a' has incomplete type
 bool cmp(struct data a, struct data b){
          ~~~~~~~~~~~~^
Main.cc:6:17: note: forward declaration of 'struct data'
 bool cmp(struct data a, struct data b){
                 ^~~~
Main.cc:6:37: error: 'b' has incomplete type
 bool cmp(struct data a, struct data b){
                         ~~~~~~~~~~~~^
Main.cc:6:17: note: forward declaration of 'struct data'
 bool cmp(struct data a, struct data b){
                 ^~~~
*/

Double click to view unformatted code.


Back to problem 134