C. Little Artem and Matrix
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.

That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.

Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.

Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.

Input

The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.

Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m,  - 109 ≤ xi ≤ 109) are given.

Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.

Output

Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.

If there are multiple valid solutions, output any of them.

Examples
Input
  1. 2 2 6
    2 1
    2 2
    3 1 1 1
    3 2 2 2
    3 1 2 8
    3 2 1 8
Output
  1. 8 2
    1 8
Input
  1. 3 3 2
    1 2
    3 2 2 5
Output
  1. 0 0 0
    0 0 5
    0 0 0
  2.  
  3. 题意:恶心模拟 3种对矩阵的操作
    1 r r行的第一个元素放到最后一个
    2 c c列的第一个元素放到最后一个
    3 r c x rc列的赋值为x
    给你q个操作 输出初始矩阵
  4.  
  5. 题解:恶心倒序模拟
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<queue>
  5. #include<stack>
  6. #include<map>
  7. #include<set>
  8. #include<algorithm>
  9. #define ll __int64
  10. #define pi acos(-1.0)
  11. #define mod 1
  12. #define maxn 10000
  13. using namespace std;
  14. int n,m,q;
  15. struct node
  16. {
  17. int type;
  18. int r,l,value;
  19. }N[];
  20. int mp[][];
  21. int exm;
  22. int main()
  23. {
  24. scanf("%d %d %d",&n,&m,&q);
  25. memset(mp,,sizeof(mp));
  26. memset(N,,sizeof(N));
  27. for(int i=;i<=q;i++)
  28. {
  29. scanf("%d",&exm);
  30. N[i].type=exm;
  31. if(exm==)
  32. scanf("%d",&N[i].r);
  33. if(exm==)
  34. scanf("%d",&N[i].l);
  35. if(exm==)
  36. scanf("%d %d %d",&N[i].r,&N[i].l,&N[i].value);
  37. }
  38. for(int i=q;i>=;i--)
  39. {
  40. if(N[i].type==)
  41. {
  42. int gg=mp[N[i].r][m];
  43. for(int j=m-;j>=;j--)
  44. mp[N[i].r][j+]=mp[N[i].r][j];
  45. mp[N[i].r][]=gg;
  46. }
  47. if(N[i].type==)
  48. {
  49. int gg=mp[n][N[i].l];
  50. for(int j=n-;j>=;j--)
  51. mp[j+][N[i].l]=mp[j][N[i].l];
  52. mp[][N[i].l]=gg;
  53. }
  54. if(N[i].type==)
  55. {
  56. mp[N[i].r][N[i].l]=N[i].value;
  57. }
  58. }
  59. for(int i=;i<=n;i++)
  60. {
  61. cout<<mp[i][];
  62. for(int j=;j<=m;j++)
  63. cout<<" "<<mp[i][j];
  64. cout<<endl;
  65. }
  66. return ;
  67. }
  1.  

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C的更多相关文章

  1. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  2. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

    C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

    E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  7. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题

    A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...

  8. Codeforces Round #348(VK Cup 2016 - Round 2)

    A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D

    D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. 50条大牛C++编程开发学习建议

    每个从事C++开发的朋友相信都能给后来者一些建议,但是真正为此进行大致总结的很少.本文就给出了网上流传的对C++编程开发学习的50条建议,总结的还是相当不错的,编程学习者(不仅限于C++学习者)如果真 ...

  2. go学习笔记-语言指针

    语言指针 定义及使用 变量是一种使用方便的占位符,用于引用计算机内存地址.取地址符是 &,放到一个变量前使用就会返回相应变量的内存地址. 一个指针变量指向了一个值的内存地址.类似于变量和常量, ...

  3. Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String

    题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...

  4. dijkstra算法学习

    dijkstra算法学习 一.最短路径 单源最短路径:计算源点到其他各顶点的最短路径的长度 全局最短路径:图中任意两点的最短路径 Dijkstra.Bellman-Ford.SPFA求单源最短路径 F ...

  5. 12 TCP服务器 进程 线程 非阻塞

    1.单进程服务器 from socket import * serSocket = socket(AF_INET, SOCK_STREAM) # 重复使用绑定的信息 serSocket.setsock ...

  6. 【面试题】2018年最全Java面试通关秘籍第五套!

    [面试题]2018年最全Java面试通关秘籍第五套! 原创 2018-04-26 徐刘根 Java后端技术 第一套:<2018年最全Java面试通关秘籍第一套!> 第二套:<2018 ...

  7. python下的自动化测试--selenium 验证码输入问题

    之前一直在研究scrapy下数据抓取,在研究ajax数据抓取时碰巧研究了一下selenium,确实很实用,不过只做scrapy下的数据抓取,不怎么合适,一是性能的损耗,一直需要开一个浏览器,二是对于爬 ...

  8. 【紫书】(UVa12563)Jin Ge Jin Qu hao

    继续战dp.不提. 题意分析 这题说白了就是一条01背包问题,因为对于给定的秒数你只要-1s(emmmmm)然后就能当01背包做了——那1s送给劲歌金曲(?).比较好玩的是这里面dp状态的保存——因为 ...

  9. 解析·NOIP·冷门 CLZ最小环

    赐予我力量,去改变我所能改变的;赐予我勇气,去接受我不能改变的;并赐予我智慧,去分辨这两者. -----安东尼达斯 NOIP的图论题中有一部分是跟图上的环有关的.蒟蒻的我在USACO上刷题时发现了一种 ...

  10. [C/C++] new/delete和malloc/free基本区别

    /**便于遗忘时复习**/ 区别一:本质 new/delete 在C++中是运算符不是函数,需要编译器支持.malloc/free是库函数,需要头文件支持,在C语言中使用. 区别二:开辟内存大小 用 ...