fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int yt=1; //test variable
  4. bool qf=false; //fast io enabled/disabled
  5.  
  6. #define input freopen("in.txt","r",stdin);
  7. #define output freopen("out.txt","w",stdout);
  8. #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);qf=true;
  9.  
  10. #define sc scanf
  11. #define pr printf
  12. #define whi while
  13. #define ll long long
  14. #define ull unsigned long long
  15. #define lld I64d
  16. #define mp make_pair
  17. #define ff first
  18. #define ss second
  19. #define vc vector
  20. #define pb push_back
  21. #define ite iterator
  22. #define str string
  23. #define bl bool
  24. #define tr true
  25. #define fl false
  26.  
  27. #define endl '\n'
  28. #define ret return
  29. #define rsort greater<int>()
  30. #define nl if(qf==tr) pr("\n");else cout<<"\n";
  31. #define test if(qf==tr) pr("TEST %d\n",yt++);else cout<<"TEST "<<yt++<<"\n";
  32. #define gcd(a,b) __gcd(a,b)
  33. #define mod 1000000007
  34.  
  35. #define all(c) c.begin(),c.end()
  36. #define sz(c) c.size()
  37. #define clr(c) c.clear()
  38. #define fd(c,a) c.find(a)
  39. #define bg(c) c.begin()
  40. #define ed(c) c.end()
  41. #define ins(c,a) c.insert(a)
  42. #define rem(c,a) c.erase(a)
  43.  
  44. #define si(n) if(qf==fl) sc("%d",&n); else cin>>n;
  45. #define sll(n) if(qf==fl) sc("%lld",&n); else cin>>n;
  46. #define pi(n) if(qf==fl) pr("%d ",n); else cout<<n<<" ";
  47. #define pll(n) if(qf==fl) pr("%lld ",n); else cout<<n<<" ";
  48.  
  49. #define tc int t;if(qf==fl) si(t) else cin>>t;whi(t--)
  50. #define ct continue;
  51. #define debug system("PAUSE");
  52. int a[109][109];
  53. pair <int,int> temp[109][109];
  54. int main()
  55. {
  56. int i,j,n,m,q,ch;
  57. sc("%d%d%d",&n,&m,&q);
  58. for(i=0;i<n;i++)
  59. {
  60. for(j=0;j<m;j++)
  61. {
  62. temp[i][j].ff=i;
  63. temp[i][j].ss=j;
  64. }
  65. }
  66. int pos,t1,t2,r,c,val;
  67. whi(q--)
  68. {
  69. sc("%d",&ch);
  70. if(ch==1) //row shift
  71. {
  72. sc("%d",&pos);
  73. pos--;
  74. t1=temp[pos][0].ff;
  75. t2=temp[pos][0].ss;
  76. for(i=0;i<m-1;i++)
  77. {
  78. temp[pos][i].ff=temp[pos][i+1].ff;
  79. temp[pos][i].ss=temp[pos][i+1].ss;
  80. }
  81. temp[pos][m-1].ff=t1;
  82. temp[pos][m-1].ss=t2;
  83. }
  84. else if(ch==2) //column shift
  85. {
  86. sc("%d",&pos);
  87. pos--;
  88. t1=temp[0][pos].ff;
  89. t2=temp[0][pos].ss;
  90. for(i=0;i<n-1;i++)
  91. {
  92. temp[i][pos].ff=temp[i+1][pos].ff;
  93. temp[i][pos].ss=temp[i+1][pos].ss;
  94. }
  95. temp[n-1][pos].ff=t1;
  96. temp[n-1][pos].ss=t2;
  97. }
  98. else
  99. {
  100. sc("%d%d%d",&r,&c,&val);
  101. r--;
  102. c--;
  103. a[temp[r][c].ff][temp[r][c].ss]=val;
  104. }
  105. }
  106. for(i=0;i<n;i++)
  107. {
  108. for(j=0;j<m;j++) pr("%d ",a[i][j]);
  109. nl
  110. }
  111. ret 0;
  112. }
  113.  
Success #stdin #stdout 0s 3596KB
stdin
2 2 6
1 2
2 1
3 1 1 1
3 1 2 2
3 2 1 3
3 2 2 4
stdout
3 2 
4 1