Pagini recente » Cod sursa (job #1569938) | Cod sursa (job #1606498) | Cod sursa (job #1155740) | Cod sursa (job #155006) | Cod sursa (job #2285864)
#include <fstream>
#include <algorithm>
#define input "cautbin.in"
#define output "cautbin.out"
using namespace std;
namespace file{
ifstream f(input);
ofstream g(output);
void close(){
f.close();
g.close();
}
}
int main(){
int n, m, p, a, r, v[100001];
file::f>>n;
for(int i=1;i<=n;i++)
file::f>>v[i];
sort(v+1,v+n+1);
file::f>>m;
for(int i=1;i<=m;i++){
file::f>>p>>a;
switch(p){
case 0: r=upper_bound(v+1,v+n+1,a)-v-1;
if (r>=1&&r<=n&&v[r]==a)
file::g<<r<<"\n";
else
file::g<<"-1\n";
break;
case 1: r=lower_bound(v+1,v+n+1,a+1)-v-1;
file::g<<r<<"\n";
break;
case 2: r=upper_bound(v+1,v+n+1,a-1)-v;
file::g<<r<<"\n";
break;
}
}
file::close();
return 0;
}