Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include<fstream>
  2. using namespace std;
  3. int v[10001];
  4. int cautb0(int p, int u, int key)
  5. {
  6. int m=(p+u)/2;
  7. while(p<u)
  8. {
  9. m=(p+u)/2;
  10. if(key<v[m])
  11. u=m-1;
  12. else p=m;
  13. }
  14. return u;
  15. }
  16.  
  17. int main()
  18. {
  19. ifstream fin("cautbin.in");
  20. ofstream fout("cautbin.out");
  21. int N, M;
  22. fin >> N;
  23. for(int i=1; i<=N; i++)
  24. fin >> v[i];
  25. fin >> M;
  26. for(int i=1; i<=M; ++i)
  27. {
  28. int type, x;
  29. fin >> type >> x;
  30. if(type==0)
  31. if(v[cautb0(v[1], v[N], x)]!=x);
  32. fout << "-1";
  33. if(type==1)
  34. fout << v[cautb0(v[1], v[N], x)];
  35. if(type==2)
  36. fout << v[cautb0(v[1], v[N], x-1)+1];
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement