#include<bits/stdc++.h> #define f for(int i=0;i<n;++i) using namespace std; struct node{ int x,id; }; bool cmp(node x,node y){ return x.x<y.x; } int main(){ int n; while(cin>>n){ struct node a[n+5]; f{ scanf("%d",&a[i].x); a[i].id=i; } int p,b,c,d;cin>>p; sort(a,a+n,cmp); while(p--){ scanf("%d %d",&b,&c); f{ d=i; if(a[i].id>=b-1&&a[i].id<=c-1) break; } printf("%d\n",a[d]); } } } |
Double click to view unformatted code.