Guest User

Untitled

a guest
Dec 29th, 2020
53
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // compile and run with:
  2. // clang++ -stdlib=libc++ main.cpp
  3. // ./a.out 1000000
  4. #include <algorithm>
  5. #include <iostream>
  6. #include <vector>
  7. int main(int argc, char** argv) {
  8.     if (argc < 2) {
  9.         std::cerr << "Must specify size\n";
  10.         return 1;
  11.     }
  12.     const int N = atoi(argv[1]);
  13.     if (N <= 0 || N % 4 != 0) {
  14.         std::cerr << "Size must be a positive multiple of 4\n";
  15.         return 1;
  16.     }
  17.     const int k = N / 2;
  18.     std::vector<int> v(N);
  19.     for (int i = 0; i < k; i++) {
  20.         if (i % 2 == 0) {
  21.             v[i] = i;
  22.         } else {
  23.             v[i] = i + k - 1;
  24.         }
  25.     }
  26.     for (int i = k; i < N; i++) {
  27.         v[i] = 2*i - 2*k + 1;
  28.     }
  29.     std::nth_element(v.begin(), v.end() - 1, v.end());
  30.  
  31.     return 0;
  32. }
  33.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×