Pagini recente » Cod sursa (job #1966434) | Borderou de evaluare (job #1051036) | Cod sursa (job #32767) | Cod sursa (job #500088) | Cod sursa (job #2507753)
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define rc(x) return cout<<x<<endl,0
#define forn(i,n) for(int i=0;i<int(n);i++)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int nmax=2e5+19;
const int mod=6669666;
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie();
freopen("cautbin.in","r",stdin);
freopen("cautbin.out","w",stdout);
int n;
cin>>n;
vector<int>v;
forn(i,n)
{
int x;
cin>>x;
v.pb(x);
}
int k;
cin>>k;
while(k--)
{
int a,b;
cin>>a>>b;
if(a==0)
{
int x=upper_bound(all(v),b)-v.begin();
if(x>=0 && x<v.size()) cout<<x<<"\n"; else cout<<"-1\n";
} else
if(a==1)
{
int x=lower_bound(all(v),b+1)-v.begin();
cout<<x<<"\n";
} else
{
int x=upper_bound(all(v),b-1)-v.begin()+1;
cout<<x<<"\n";
}
}
}