Pagini recente » Cod sursa (job #2122263) | Cod sursa (job #222991) | Cod sursa (job #525439) | Cod sursa (job #2683572) | Cod sursa (job #2263693)
#include <bits/stdc++.h>
#define MaxN 100005
std::ifstream InFile("cautbin.in");
std::ofstream OutFile("cautbin.out");
int N, Q, V[MaxN];
int main()
{
InFile >> N;
for (int i=0; i<N; ++i)
InFile >> V[i+1];
InFile >> Q;
int Type, x, p;
while (Q--) {
InFile >> Type >> x;
if (Type == 0) {
p = std::upper_bound(V+1, V+N+1, x) - V-1;
if (V[p] != x) p = -1;
} else
if (Type == 1) {
p = std::upper_bound(V+1, V+N+1, x) - V-1;
} else
if (Type == 2) {
p = std::lower_bound(V+1, V+N+1, x) - V;
}
OutFile << p << '\n';
}
return 0;
}