Pagini recente » Cod sursa (job #1849742) | Cod sursa (job #456865) | Cod sursa (job #2567255) | Cod sursa (job #2564036) | Cod sursa (job #1146525)
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, m, x, y, type, sir[100100];
int main()
{
f >> n;
for(int i = 1; i <= n; ++i)
f >> sir[i];
f >> m;
while(m--)
{
f >> type >> y;
if(type == 0)
{
x = upper_bound(sir + 1, sir + n + 1, y) - sir - 1;
if(x > 0 && x <= n && sir[x] == y)
g << x << "\n";
else
g << "-1\n";
}
else if(type == 1)
{
x = lower_bound(sir + 1, sir + n + 1, y + 1) - sir - 1;
g << x << '\n';
}
else
{
x = upper_bound(sir + 1, sir + n + 1, y - 1) - sir;
g << x << '\n';
}
}
}