Pagini recente » Cod sursa (job #1032840) | Cod sursa (job #1609845) | Cod sursa (job #2781940) | Cod sursa (job #2144433) | Cod sursa (job #1018841)
#include<iostream>
#include<fstream>
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int n, v[10100100], k, x, y, poz;
int cbin1(int a, int b){
int m;
while(a<=b){
m=(a+b)/2;
if(y>=v[m]) {a=m+1; if(y==v[m])poz=m;}
else b=m-1;
}
if(!poz) return -1;
else return b;
}
int cbin2(int a, int b){
int m;
while(a<=b){
m=(a+b)/2;
if(y>v[m]) {a=m+1; poz=m;}
else b=m-1;
}
poz=a;
if(!poz) return -1;
else return poz;
}
int main()
{
f>>n;
for(int i=1; i<=n; ++i)
f>>v[i];
f>>k;
for(int i=0; i<k; ++i){
f>>x>>y;
if(x==0){poz=0; g<<cbin1(1, n)<<'\n';}
else if(x==1) {poz=0; cbin1(1, n); g<<poz<<'\n';}
else {poz=0; cbin2(1, n); g<<poz;}
}
return 0;
}