Niloy007

Sazzad's problem in O(logn)

Jun 4th, 2020
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     vector<int> arr = {1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 5, 8, 9};
  6.  
  7.     int n;
  8.     cin >> n;
  9.     int indexOne = lower_bound(arr.begin(), arr.end(), n) - arr.begin();
  10.     int indexTwo = upper_bound(arr.begin(), arr.end(), n) - arr.begin();
  11.     int result = indexTwo - indexOne;
  12.     cout << n << " occurs " <<  result << " time" << endl;
  13.  
  14.     return 0;
  15. }
RAW Paste Data