fork download
  1. #include <bits/stdc++.h>
  2. #define FOR(i,start,end,jump) for(int i=(start),_end=(end);i<=_end;i+=(jump))
  3. #define fi first
  4. #define se second
  5. #define ps(any) push_back(any)
  6. using namespace std;
  7.  
  8. const int maxn=1e4+3;
  9.  
  10. int k,u,v,p,q,t,n=0,f[maxn][103],check,cnt,loop=maxn,idx1,idx2;
  11. string s;
  12.  
  13.  
  14. void READ(){
  15. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  16. freopen("DAYSO.inp","r",stdin);
  17. freopen("DAYSO.out","w",stdout);
  18. cin>>k>>u>>v>>p>>q;
  19. getline(cin,s);
  20. getline(cin,s);
  21. istringstream ss(s);
  22. while(ss>>t) f[0][++n]=t;
  23. idx2=max(q,v);
  24. idx1=min(u,p);
  25. check=idx2-idx1+1;
  26. }
  27.  
  28. void DO(){
  29. k+=k;
  30. FOR(i,1,k,1)
  31. {
  32. cnt=0;
  33. if(i%2==1){
  34. u--;
  35. FOR(j,1,u,1) f[i][j]=f[i-1][j];
  36. u++;
  37. FOR(j,u,v,1) f[i][v-j+u]=f[i-1][j];
  38. v++;
  39. FOR(j,v,n,1) f[i][j]=f[i-1][j];
  40. v--;
  41. }
  42. else{
  43. p--;
  44. FOR(j,1,p,1) f[i][j]=f[i-1][j];
  45. p++;
  46. FOR(j,p,q,1) f[i][q-j+p]=f[i-1][j];
  47. q++;
  48. FOR(j,q,n,1) f[i][j]=f[i-1][j];
  49. q--;
  50. }
  51. FOR(j,idx1,idx2,1) if(f[i][j]==f[0][j]) cnt++;
  52. if(cnt==check) {loop=i;break;}
  53. }
  54. k%=loop;
  55. // FOR(i,1,loop,1){
  56. // FOR(j,1,n,1) cout<<f[i][j]<<" ";
  57. // cout<<'\n';
  58. // }
  59. // cout<<loop;
  60. FOR(i,1,n,1) cout<<f[k][i]<<" ";
  61. }
  62.  
  63. int main()
  64. {
  65. READ();
  66. DO();
  67. }
  68.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty