Pagini recente » Cod sursa (job #3238681) | Cod sursa (job #891713) | Cod sursa (job #18509) | Cod sursa (job #2276682) | Cod sursa (job #2252159)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("cautbin.in");
ofstream fout ("cautbin.out");
int main()
{
vector <long long> v;
int n, m, op;
long long x;
fin >> n;
for (int i = 0; i < n; i++)
{
fin >> x;
v.push_back(x);
}
fin >> m;
for (int i = 1; i <= m; i++)
{
fin >> op >> x;
if (op == 0)
{
int ind = upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
if (v[ind] != x)
{
fout << -1 << "\n";
}
else fout << ind + 1 << "\n";
}
else if (op == 1)
{
if (binary_search(v.begin(), v.end(), x))
fout << upper_bound(v.begin(), v.end(), x) - v.begin() << "\n";
else fout << lower_bound(v.begin(), v.end(), x) - v.begin() << "\n";
}
else if (op == 2)
{
if (binary_search(v.begin(), v.end(), x))
{
fout << lower_bound(v.begin(), v.end(), x) - v.begin() + 1 << "\n";
}
else fout << upper_bound(v.begin(), v.end(), x) - v.begin() + 1 << "\n";
}
}
return 0;
}