Pagini recente » Profil aplace4uhead | Statistici Stefan (SaltySalt) | Atasamentele paginii Rezultate Algorel | Monitorul de evaluare | Cod sursa (job #2969968)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n;
cin >> n;
vi a(n);
for(int i = 0; i < n; i++)
cin >> a[i];
int m;
cin >> m;
for(int i = 0; i < m; i++){
int x, b;
cin >> x >> b;
if(x == 0){
auto h = upper_bound(a.begin(), a.end(), b);
--h;
if(*h == b)
cout << h - a.begin() + 1 << '\n';
else
cout << -1 << '\n';
} else if(x == 1){
auto h = upper_bound(a.begin(), a.end(), b);
--h;
cout << h - a.begin() + 1 << '\n';
} else {
auto h = lower_bound(a.begin(), a.end(), b);
cout << h - a.begin() + 1 << '\n';
}
}
}
int main(){
freopen("cautbin.in", "r", stdin);
freopen("cautbin.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}