Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- using namespace std;
- int v[10001];
- int cautb0(int p, int u, int key)
- {
- int m=(p+u)/2;
- while(p<u)
- {
- m=(p+u)/2;
- if(key<v[m])
- u=m-1;
- else p=m;
- }
- return u;
- }
- int main()
- {
- ifstream fin("cautbin.in");
- ofstream fout("cautbin.out");
- int N, M;
- fin >> N;
- for(int i=1; i<=N; i++)
- fin >> v[i];
- fin >> M;
- for(int i=1; i<=M; ++i)
- {
- int type, x;
- fin >> type >> x;
- if(type==0)
- if(v[cautb0(v[1], v[N], x)]!=x);
- fout << "-1";
- if(type==1)
- fout << v[cautb0(v[1], v[N], x)];
- if(type==2)
- fout << v[cautb0(v[1], v[N], x-1)+1];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement