Advertisement
gurenko

Untitled

Jun 20th, 2024
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <cstdint>
  4. #include <iostream>
  5. #include <random>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. int EffectiveCount(const vector<int>& v, int n, int i) {
  11.     // место для вашего решения
  12.  
  13. //    auto tmp = v.begin();
  14.     // auto tmp = static_cast<int64_t>(v.size())*(i + 1)/(n + 1);
  15.  
  16.     if (static_cast<int64_t>(v.size())*(i + 1)/(n + 1) <= log2(v.size())){
  17.         auto iter = find_if(v.begin(), v.end(),[i](int element){
  18.             return element > i;
  19.         });
  20.         return std::distance(v.begin(), iter);
  21.     } else{
  22.         auto iter = upper_bound(v.begin(), v.end(), i) ;
  23.         return std::distance(v.begin(), iter);
  24.     }
  25.  
  26.  
  27. }
  28.  
  29. int main() {
  30.     // static const int NUMBERS = 1'000'000;
  31.     // static const int MAX = 1'000'000'000;
  32.     static const int NUMBERS = 10'000;
  33.    static const int MAX = 4999;
  34.  
  35.    mt19937 r;
  36.    uniform_int_distribution<int> uniform_dist(0, MAX);
  37.  
  38.    vector<int> nums;
  39.    for (int i = 0; i < NUMBERS; ++i) {
  40.        int random_number = uniform_dist(r);
  41.        nums.push_back(random_number);
  42.    }
  43.    sort(nums.begin(), nums.end());
  44.  
  45.    int i;
  46.    cin >> i;
  47.    int result = EffectiveCount(nums, MAX, i);
  48.    cout << "Total numbers before "s << i << ": "s << result << endl;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement