Pagini recente » Cod sursa (job #2601330) | Cod sursa (job #682048) | Cod sursa (job #3228438) | Cod sursa (job #3134911) | Cod sursa (job #2638168)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int nmax=100005;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x) return cout<<x<<"\n",0
#define sz(s) (int) s.size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
using namespace std;
ll a[nmax];
ll t,n;
int caut0(int x) {
ll l=1,r=n;
ll mid=l+(r-l)/2,ans;
while (l<=r) {
if (a[mid]<=x) {
l=mid+1;
ans=mid;
}
else {
r=mid-1;
}
mid=l+(r-l)/2;
}
if (a[ans]!=x)return -1;
return ans;
}
int caut1(int x) {
ll l=1,r=n;
ll mid=l+(r-l)/2;
while (l<=r) {
if (a[mid]<=x) {
l=mid+1;
}
else {
r=mid-1;
}
mid=l+(r-l)/2;
}
return r;
}
int caut2(int x) {
ll l=1,r=n;
ll mid=l+(r-l)/2;
while (l<=r) {
if (a[mid]<x) {
l=mid+1;
}
else {
r=mid-1;
}
mid=l+(r-l)/2;
}
return l;
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ifstream cin("cautbin.in");
ofstream cout("cautbin.out");
cin >> n;
for (int i=1; i<=n; i++) {
cin >> a[i];
}
ll m;
cin >> m;
while (m--) {
ll x,a;
cin >> x >> a;
if (x==0) {
cout << caut0(a) << '\n';
}
if (x==1) {
cout << caut1(a) << '\n';
}
if (x==2) {
cout << caut2(a) << '\n';
}
}
}