IMohammedNasr

C. Playing With Cards

Sep 24th, 2022
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(v) for (auto &i : v) cin >> i;
  4. #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
  5. #define ll long long
  6. #define all(v) v.begin(), v.end()
  7. #define rall(v) v.rbegin(), v.rend()
  8. #define MOD 1000000007
  9. #define Ceil(a,b) a / b + (a % b != 0)
  10. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
  11.  
  12. void Warding()
  13. {
  14.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  15. #ifndef ONLINE_JUDGE
  16.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  17. #endif
  18. }
  19.  
  20. /*
  21. STOP USING int  
  22. */
  23.  
  24.  
  25. void solve(){
  26.     ll n, k; cin>>n>>k;
  27.     vector<ll> v(n); cin(v);
  28.     ll times = ((n + 1) / 2), cycles = k / (times), change = k % times;
  29.     bool flip = (cycles & 1);
  30.     for(int i=0; i<Ceil(n,2); i++){
  31.         if(i < change){
  32.             if(!flip)
  33.             swap(v[i],v[n - i - 1]);
  34.         }else if(flip){
  35.             swap(v[i], v[n - i - 1]);
  36.         }
  37.     }
  38.     cout(v);
  39. }
  40.  
  41. int main()
  42. {
  43.     Warding();
  44.     int TC = 1;
  45.     cin >> TC;
  46.     while (TC--)
  47.     {
  48.         solve();
  49.     }
  50.     Time
  51. }
Advertisement
Add Comment
Please, Sign In to add comment