Pagini recente » Cod sursa (job #1516343) | Cod sursa (job #2041595) | Cod sursa (job #323250) | Cod sursa (job #1838999) | Cod sursa (job #2876888)
#include <iostream>
#include <fstream>
#include <stdio.h>
#define LIM 1<<17
using namespace std;
char BUF[LIM];
int poz;
inline char getChar()
{
poz++;
if(poz>=LIM)
{
fread(BUF,LIM,1,stdin);
poz=0;
}
return BUF[poz];
}
inline int getNr()
{
int r=0, semn=1;
char ch=getChar();
while(isdigit(ch)==0 && ch!='-') ch=getChar();
if(ch=='-')
{
semn=-1;
ch=getChar();
}
while(isdigit(ch)!=0)
{
r=r*10+semn*(ch-'0');
ch=getChar();
}
return r;
}
ofstream fout ("cautbin.out");
int v[100001];
int main()
{
freopen("cautbin.in","r",stdin);
int n, m, x, pas, j, q;
poz=LIM;
n = getNr();
for (int i=1;i<=n;i++)
v[i]=getNr();
m = getNr();
for (int i=1;i<=m;i++) {
q = getNr();
x = getNr();
if (q==0) {
j=1;
pas=1<<16;
while (pas>0) {
if (j+pas<=n && v[j+pas]<=x) {
j+=pas;
}
pas/=2;
}
if (v[j]==x)
fout<<j<<'\n';
else
fout<<-1<<'\n';
}
else if (q==1) {
j=1;
pas=1<<16;
while (pas>0) {
if (j+pas<=n && v[j+pas]<=x) {
j+=pas;
}
pas/=2;
}
fout<<j<<'\n';
}
else{
j=1;
pas=1<<16;
while (pas>0) {
if (j+pas<=n && v[j+pas]<x) {
j+=pas;
}
pas/=2;
}
fout<<j+1<<'\n';
}
}
return 0;
}