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