Advertisement
tepyotin2

!!!TTT P51 Swapity Swapity Swap #1014

Nov 9th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. vector<int> ori, cur;
  6. vector<pair<int, int>> ord;
  7. int N, M, K;
  8. bool isDiag = false;
  9. vector<int> apply(vector<int> v){
  10.    
  11.     for (int i = 0; i < M; i++)
  12.     {
  13.         reverse(begin(v)+ord[i].first-1, begin(v)+ord[i].second);
  14.     }
  15.    
  16.     return v;
  17. }
  18. int main(){
  19.     freopen("swap.in", "r", stdin);
  20.    
  21.     cin >> N >> M >> K;
  22.     for (int i = 1; i <= N; i++)
  23.     {
  24.         ori.push_back(i);
  25.     }
  26.    
  27.  
  28.     for (int i = 0; i < M; i++)
  29.     {
  30.         int L, R;
  31.         cin >> L >> R;
  32.         ord.push_back({L, R});
  33.     }
  34.    
  35.    
  36.     cur = ori;
  37.     int period = 0;
  38.     do
  39.     {
  40.         period ++ ;
  41.         cur = apply(cur);
  42.     } while (cur != ori);
  43.    
  44.    
  45.     int k = K%period;
  46.    
  47.     while (k--)
  48.     {
  49.         cur = apply(cur);
  50.     }
  51.    
  52.     freopen("swap.out", "w", stdout);
  53.     for (int i = 0; i < N; i++)
  54.     {
  55.         cout << cur[i] << endl;
  56.     }
  57.    
  58.    
  59.    
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement