fork download
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <map>
  5. #include <climits>
  6. #include <algorithm>
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11. int n, x;cin >> n >> x;
  12.  
  13. vector<int> v;
  14. for (int i = 0;i < n;i++) {
  15. int value;cin >> value;
  16. v.push_back(value);
  17. }
  18.  
  19. auto itOne = lower_bound(v.begin(), v.end(), x);
  20. if (itOne != v.end()) {
  21. cout << distance(v.begin(), itOne) << endl;
  22. }
  23. else{
  24. cout << -1 << endl;
  25. }
  26.  
  27. auto itTwo = upper_bound(v.begin(), v.end(), x);
  28. if (itTwo != v.end()) {
  29. cout << distance(v.begin(), itTwo) << endl;
  30. }
  31. else {
  32. cout << -1 << endl;
  33. }
  34.  
  35. auto itThree = lower_bound(v.begin(), v.end(), x);
  36. if (*itThree == x) {
  37. cout << distance(v.begin(), itThree) << endl;
  38. }
  39. else {
  40. cout << -1 << endl;
  41. }
  42.  
  43. auto itFour = upper_bound(v.begin(), v.end(), x);
  44. itFour--;
  45. if (*itFour == x) {
  46. cout << distance(v.begin(), itFour) << endl;
  47. }
  48. else {
  49. cout << -1 << endl;
  50. }
  51.  
  52. cout << distance(itThree, itFour) + 1;
  53. return 0;
  54. }
Success #stdin #stdout 0s 712KB
stdin
Standard input is empty
stdout
-1
-1
-1
-1
0