Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <time.h>
  3. //#include <random>
  4. //#ifndef _LOCAL
  5. //#pragma GCC optimize("-O3")
  6. //#pragma GCC optimize("Ofast")
  7. //#pragma GCC optimize("unroll-loops")
  8. //#endif
  9. #define sz(x) int(x.size())
  10. #define in(x) freopen(x, "r", stdin)
  11. #define out(x) freopen(x, "w", stdout)
  12. #define N 2 * 100500
  13. #define oo ll(1e16)
  14. #define pii pair <int, int>
  15. #define pll pair <ll, ll>
  16. #define ft first
  17. #define sd second
  18. #define pb push_back
  19. #define ppb pop_back
  20. #define el '\n'
  21. #define elf endl
  22. #define base ll(1e9 + 7)
  23. #define re return
  24. #define nins 4294967295
  25. using namespace std;
  26. typedef long long ll;
  27. typedef long double ld;
  28. const int LOG = 20;
  29.  
  30. //mt19937 rnd(0);
  31.  
  32. int n, p[N], a[N], cur, kol, siz, m;
  33. vector <int> rs;
  34.  
  35. void solve() {
  36.     cin >> n;
  37.     for (int i = 0; i < n; i++)
  38.         cin >> a[i];
  39.  
  40.     for (int i = 0; i < n - 1; i++)
  41.         p[i] = i + 1;
  42.  
  43.     p[n - 1] = 0;
  44.  
  45.     cin >> m;
  46.  
  47.     cur = 0;
  48.     kol = 1;
  49.     siz = n;
  50.     while (siz > 1)
  51.         if (kol + 1 == m) {
  52.             kol = 1;
  53.             p[cur] = p[p[cur]];
  54.             siz--;
  55.             cur = p[cur];
  56.         } else kol++, cur = p[cur];
  57.  
  58.     bool odd = cur & 1;
  59.  
  60.     for (int i = 0; i < n; i++)
  61.         if ((a[i] & 1) == odd)
  62.             rs.pb(a[i]);
  63.  
  64.     sort(rs.begin(), rs.end());
  65.  
  66.     for (int i = 0; i < sz(rs); i++)
  67.         cout << rs[i] << ' ';
  68. }
  69.  
  70. int main() {
  71.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  72.     #ifdef _LOCAL
  73.         in("input.txt");
  74.  
  75.         int t = 1;
  76. //        cin >> t;
  77.         for (int i = 1; i <= t; i++) {
  78.             cout << "Test #" << i << elf;
  79.  
  80.             clock_t start_time = clock();
  81.  
  82.             solve();
  83.  
  84.             cerr.precision(4); cerr << fixed;
  85.             cerr << elf;
  86.             cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << elf;
  87.  
  88.             cout << elf;
  89.         }
  90.     #else
  91.         int t = 1;
  92. //        cin >> t;
  93.  
  94.         while (t--) {
  95.             solve();
  96.             cout << el;
  97.         }
  98.     #endif
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement