Advertisement
Niloy007

Sazzad's problem in O(logn)

Jun 4th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement