fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAXN = 1005;
  5. int n, m, q;
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cout.tie(0);
  11.  
  12. cin >> n >> m >> q;
  13. vector<vector<int>> A(n + 1, vector<int>(m + 1));
  14. vector<long long> hang(n + 1, 0), cot(m + 1, 0);
  15. vector<int> row(n + 1);
  16. for (int i = 1; i <= n; ++i) {
  17. row[i] = i;
  18. for (int j = 1; j <= m; ++j) {
  19. cin >> A[i][j];
  20. hang[i] += A[i][j];
  21. cot[j] += A[i][j];
  22. }
  23. }
  24.  
  25. while (q--) {
  26. string type;
  27. cin >> type;
  28. if (type == "1") {
  29. int i, j;
  30. cin >> i >> j;
  31. swap(row[i], row[j]);
  32. swap(hang[i], hang[j]);
  33. } else if (type == "2") {
  34. int i, j, x;
  35. cin >> i >> j >> x;
  36. int real_i = row[i];
  37. hang[i] += x - A[real_i][j];
  38. cot[j] += x - A[real_i][j];
  39. A[real_i][j] = x;
  40. } else if (type == "r") {
  41. int i;
  42. cin >> i;
  43. cout << hang[i] << '\n';
  44. } else if (type == "c") {
  45. int j;
  46. cin >> j;
  47. cout << cot[j] << '\n';
  48. }
  49. }
  50.  
  51. for (int i = 1; i <= n; ++i) {
  52. int real_i = row[i];
  53. for (int j = 1; j <= m; ++j) {
  54. cout << A[real_i][j] << " ";
  55. }
  56. cout << '\n';
  57. }
  58.  
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty