Pagini recente » Cod sursa (job #2963069) | Cod sursa (job #2516809) | Cod sursa (job #1007102) | Cod sursa (job #1707645) | Cod sursa (job #2378673)
#include <bits/stdc++.h>
#define NM 100005
using namespace std;
ifstream f("cautbin.in");
ofstream g("cautbin.out");
int v[NM],vmin[NM],vmax[NM];
int main()
{ int n;
f>>n;
for(int i=1; i<=n; i++) f>>v[i];
int k;
f>>k;
while(k--)
{ int t,x,poz=-1;
f>>t>>x;
if(!t)
{ int lw=lower_bound(v+1,v+n+1,x)-v;
int up=upper_bound(v+1,v+n+1,x)-v;
if(up-lw) poz=up-1;
g<<poz<<'\n';
}
else
{ bool ok=false;
do
{ int lw=lower_bound(v+1,v+n+1,x)-v;
int up=upper_bound(v+1,v+n+1,x)-v;
if(up-lw) ok=true;
else
if(t==1) x--;
else x++;
}
while(!ok);
int up=upper_bound(v+1,v+n+1,x)-v;
int lw=lower_bound(v+1,v+n+1,x)-v;
if(t==1) g<<up-1<<'\n';
else g<<lw<<'\n';
}
}
return 0;
}