Pagini recente » Cod sursa (job #296963) | Cod sursa (job #42279) | Cod sursa (job #313814) | Cod sursa (job #3271856) | Cod sursa (job #3286446)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fcin("cautbin.in");
ofstream fout("cautbin.out");
int n, m, cartof[100001];
void B0(int y)
{
int z = upper_bound(cartof + 1, cartof + n + 1, y) - cartof - 1;
if (cartof[z]!=y)
fout<<-1<<"\n";
else
fout<<z<<"\n";
}
void B1(int y)
{
int z = upper_bound(cartof + 1, cartof + n + 1, y) - cartof - 1;
fout<<z<<"\n";
}
void B2(int y)
{
int z = lower_bound(cartof + 1, cartof + n + 1, y) - cartof;
fout<<z<<"\n";
}
int main()
{
fcin>>n;
for (int i=1; i<=n; i++)
fcin>>cartof[i];
fcin>>m;
for (int i=1; i<=m; i++)
{
int x, y;
fcin>>x>>y;
if (x==0)
B0(y);
if (x==1)
B1(y);
if (x==2)
B2(y);
}
return 0;
}