Pagini recente » Cod sursa (job #1363333) | Cod sursa (job #1269104) | Rotatie lexicografic minima | Cod sursa (job #1758207) | Cod sursa (job #2485760)
#include<bits/stdc++.h>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, m;
vector<int> v;
int main()
{
f>>n;
for(int i = 0 ; i < n ; i++){
int x;
f>>x;
v.push_back(x);
}
f>>m;
for(int i = 0 ; i < m ; i++){
int question, x, y;
f>>question>>x;
if(question == 0){
y = upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
if(v[y] == x && y >= 0 && y <= n){
g<<y + 1<<'\n';
}
else{
g<<-1<<'\n';
}
}
else if(question == 1){
y = lower_bound(v.begin(), v.end(), y + 1) - v.begin() - 1;
g<<y + 1<<'\n';
}
else {
y = upper_bound(v.begin(), v.end(), y - 1) - v.begin();
g<<y + 1<<'\n';
}
}
return 0;
}