Pagini recente » Cod sursa (job #1835369) | Cod sursa (job #3180564) | Cod sursa (job #3278645) | Cod sursa (job #879962) | Cod sursa (job #3157690)
#include <bits/stdc++.h>
#define MAX 100000
using namespace std;
ifstream fin("cautbin.in");
ofstream fout("cautbin.out");
int v[MAX+1];
int m, n, c, x;
int main()
{
fin >> n;
for(int i=0; i<n; i++)fin >> v[i];
fin >> m;
for(int i=0; i<m; i++)
{
fin >> c >> x;
if(c==0)
{
int pos = upper_bound(v,v+n,x)-v-1;
if(v[pos]==x)fout << pos+1 << '\n';
else fout << -1 << '\n';
}
else if(c==1)
{
int pos = lower_bound(v,v+n,x)-v;
if(v[pos]<x)fout << pos+1 << '\n';
if(v[pos]==x)
{
while(v[pos]==x)pos++;
fout << pos << '\n';
}
}
else if(c==2)
{
int pos=lower_bound(v,v+n,x)-v;
fout << 1+pos << '\n';
}
}
return 0;
}